Consume RESTFUL web service and perform post operation. RRS feed

All replies

  • User1323099333 posted

    Hi All,

    I have written below code to update data using service and getting  error. Can some one please help?


    string coreURL = "https://testservice.com/My_partners?action=confirm_contact&userid=AAA0001&update_by=AAA0001";

                string strURL = " https://testservice.com/My_partners?action=confirm_contact";

                string userid = " AAA0001";

                //byte[] dataByte = Encoding.UTF8.GetBytes("&&userid="+userid);



                HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(strURL);

                //Method type

                POSTRequest.Method = "PUT";

                // Data type - message body coming in xml

                POSTRequest.ContentType = "application/x-www-form-urlencoded";

                POSTRequest.KeepAlive = false;

                POSTRequest.Timeout = 5000;

                //Content length of message body



                // Get the request stream

                Stream POSTstream = POSTRequest.GetRequestStream();

                // Write the data bytes in the request stream

                byte[] dataByte = Encoding.UTF8.GetBytes("&userid=" + userid);

                //POSTRequest.ContentLength = dataByte.Length;

                POSTstream.Write(dataByte, 0, dataByte.Length);


                dataByte = Encoding.UTF8.GetBytes("&update_by=" + userid);

               // POSTRequest.ContentLength = dataByte.Length;

                POSTstream.Write(dataByte, 0, dataByte.Length);



                //Get response from server

                HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();

                StreamReader reader =

                  new StreamReader(POSTResponse.GetResponseStream(), Encoding.UTF8);




    when I execute above code receiving error 400.


    Can some one please help me.


    Saturday, June 8, 2013 2:07 AM