Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612942
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:28:29+00:00 2026-05-22T01:28:29+00:00

I am updating the db table on force.com using Rest API. And i am

  • 0

I am updating the db table on force.com using Rest API. And i am posting json data to update db table like this.

     // preparing webrequest
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

      // adding request headers
      request.ContentType = "application/json";
      request.Headers["Authorization"] = "OAuth " + token;
      request.Headers["X-PrettyPrint"] = "1";
      // request method
      request.Method = "PATCH";
       // start the asynchronous operation
                request.BeginGetRequestStream(new AsyncCallback(SaveBeginGetRequestStreamCallBack), request);


 private void SaveBeginGetRequestStreamCallBack(IAsyncResult ar)
        {

            HttpWebRequest webRequest = (HttpWebRequest)ar.AsyncState;

            Stream postStream = webRequest.EndGetRequestStream(ar);

            (using (StreamWriter sw = new StreamWriter(postStream))
            {
                 sw.Write(postData);
                // postData is in json format like: {"Name":"Michel"}  
            }

           postStream.close(); 
            webRequest.BeginGetResponse(new AsyncCallback(SaveBeginGetResponseCallback), webRequest);
        }

        private void SaveBeginGetResponseCallback(IAsyncResult ar)
        {

            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)ar.AsyncState;
                HttpWebResponse response;

                // End the get response operation
                response = (HttpWebResponse)webRequest.EndGetResponse(ar);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(streamResponse);
                string Response = streamReader.ReadToEnd();
                streamResponse.Close();
                streamReader.Close();
                response.Close();

            }
            catch (WebException e)
            {
                MessageBox.Show(e.Message);
                // Error treatment

            }

But it is showing bad request error. Is it a right way to send json format over http request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:28:30+00:00Added an answer on May 22, 2026 at 1:28 am

    You are not closing/disposing the postStream prior to calling BeginGetResponse …

    Also, call

    sw.Write(data);
    

    Since data is a string. Your call (passing an offset and a count) would be appropriate for a byte array. You are actually calling a formatting overload http://msdn.microsoft.com/en-us/library/fd857wct(v=VS.96).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am updating a table in mysql using ADODB i am adding new entries
I am having difficulty updating a table via PHP. Using MySQL prompt or a
I am using greasemonkey script and have updating the table using following code. I
I am updating my table with the following statement: UPDATE table SET percentage =
I'm working on an auto-updating table of information using AJAX, but I've run into
I am having problem updating table cell value using jQuery 1.4.2. it all works
I have created a small test for updating table using Linq-to-SQL DataContext as follows:
I have problem with updating my datagridview after inserting new data to table. It
Suppose you're updating a table that is the result of an expression, like so
Using JPA/Eclipse TopLink. I'm updating a table (using createNativeQuery) as shown below: Query query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.