您的位置:首页 > 其它

webclient在访问期间出现异常,报错! 无法发送具有此谓词类型的内容正文

2014-06-09 18:23 639 查看
原因是:你采用了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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐