System.Net.WebException: 远程服务器返回错误: (400) 错误的请求。
基本上属于你请求的Request内容不正确导致的,比如应该用POST的地方用了GET,
还有可能是POST/GET的content-type不正确
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项目!