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/
如: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/
相关文章推荐
- webclient在访问期间出现 异常,报错! 无法发送具有此谓词类型的内容正文。
- 【异常记录(五)】C# 无法发送具有此谓词类型的内容正文错误
- httpwebresponse 异步: request.BeginGetRequestStream 报错! 无法发送具有此谓词类型的内容正文。
- httpwebresponse 异步: request.BeginGetRequestStream 报错! 无法发送具有此谓词类型的内容正文。
- httpwebrequest 用GET方法时报无法发送具有此谓词类型的内容正文
- 无法发送具有此谓词类型的内容正文
- httpwebrequest 用GET方法请求时报无法发送具有此谓词类型的内容正文
- 如何解决 Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- 如何解决 Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- 导出Excel,出现“服务器无法在发送HTTP标头之后设置内容类型”
- 用Java进行GUI设计,出现对必需的库 rt.jar 具有一定限制,因此无法访问类型 JButton等问题
- 如何解决 Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- 如何解决 Eclipse中出现-访问限制由于对必需的库XX具有一定限制,因此无法访问类型
- 压力测试中出现:“Too many open files”异常导致weblogic无法继续正常访问
- 访问限制:由于对必需的库 F:\Program Files\Java\jre6\lib\rt.jar 具有一定限制,因此无法访问类型 AWTUtilities
- Maven编译jar出现:无法确定 T 的类型参数的异常的原因和处理方案
- 访问限制:由于对必需的库 C:/Program Files/Java/jre6/lib/rt.jar 具有一定限制,因此无法访问类型 AudioPlayer