首页 新闻 会员 周边 捐助

System.Net.WebException: 远程服务器返回错误: (400) 错误的请求。

1
悬赏园豆:10 [已解决问题] 解决于 2015-10-21 10:57

System.Net.WebException: 远程服务器返回错误: (400) 错误的请求。

西瓜凉了半个夏的主页 西瓜凉了半个夏 | 初学一级 | 园豆:7
提问于:2015-10-20 09:30
< >
分享
最佳答案
0

基本上属于你请求的Request内容不正确导致的,比如应该用POST的地方用了GET, 
还有可能是POST/GET的content-type不正确

收获园豆:10
稳稳的河 | 老鸟四级 |园豆:4216 | 2015-10-20 09:51
 1  request.Accept = "application/json";
 2             request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
 3             request.Method = "POST";
 4             data.Append("uu");
 5             data.Append("=");
 6             data.Append("UU20150820124229");
 7             data.Append("&");
 8             data.Append("MD5Code");
 9             data.Append("=");
10             data.Append(ret);
11             byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
12             using (Stream postStream = request.GetRequestStream())
13             {
14                 postStream.Write(byteData, 0, byteData.Length);
15             }
16             using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
17             {
18                 // Get the response stream  .
19 
20                 StreamReader reader = new StreamReader(response.GetResponseStream());
21                 string responseStr = reader.ReadToEnd();
22                 if (responseStr != null && responseStr.Length > 0)
23                 {
24                     Dictionary<string, object> responseResult = new Dictionary<string, object> { { "statusCode", "0" }, { "statusMsg", "成功" }, { "data", responseStr } };
25                     Order o = JsonConvert.DeserializeObject<Order>(responseStr);
26                 }
27 
28                 code = responseStr;
29             }

之前是可以访问到的,就是做了系统之后访问不到,两个VS项目!

西瓜凉了半个夏 | 园豆:7 (初学一级) | 2015-10-20 10:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册