错误请求 400 - 对网站的 httpweb 请求
我正在向一个站点发出请求,他们正在使用 JSON 来交换数据。因此,我提出了以下请求,但它给出了错误 - 远程服务器返回了错误:(400) 错误请求。
URL3 是一个字符串
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();
请帮助我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论