原因是:你采用了post方式发送请求,可是在url后面带了参数
如:http://www.baidu.com?test=qq&ppk=dsafads;jfk
若是你的url类似上面的格式,则用post请求就会报错,
解决方法
1:get请求
WebClient client = new WebClient();
String jsonResult = client.DownloadString(url);
2:post请求
string postData = postParam;//传递的参数例如postParam="test=123&helo=99fgf"
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData);
String jsonResult = client.uploaddata(url,"post",bytes);//注意这里的url是不包含任何参数的,例如::http://www.baidu.com/
如:http://www.baidu.com?test=qq&ppk=dsafads;jfk
若是你的url类似上面的格式,则用post请求就会报错,
解决方法
1:get请求
WebClient client = new WebClient();
String jsonResult = client.DownloadString(url);
2:post请求
string postData = postParam;//传递的参数例如postParam="test=123&helo=99fgf"
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData);
String jsonResult = client.uploaddata(url,"post",bytes);//注意这里的url是不包含任何参数的,例如::http://www.baidu.com/