I am making a request to a site, they are using JSON for exchanging data. Hence I made the following request but it is giving an error -The remote server returned an error: (400) Bad Request.
URL3 is a string
httpWebRequest = (HttpWebRequest)WebRequest.Create(URL3);
httpWebRequest.Method = "POST";
httpWebRequest.Host = "url";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, 开发者_高级运维 like Gecko) Chrome/13.0.782.112 Safari/535.1";
httpWebRequest.KeepAlive = true;
httpWebRequest.ContentType = "application/json; charset=UTF-8";
httpWebRequest.Referer = "url2";
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
httpWebRequest.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
string postData = "";
postData += "{\"prefixText\":\"hyderabad\",\"count\":10,\"contextKey\":\"45\"}";
StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
requestWriter.Write(postData); //posting the data
requestWriter.Close();
**httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();**
responseStreamReader = new StreamReader(httpWebResponse.GetResponseStream());
string responseData_3 = responseStreamReader.ReadToEnd();
responseStreamReader.Close();
Please help me.
精彩评论