首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

关于httpclient定制对象RequestEntity和RequestBody引发的有关问题

2012-12-19 
关于httpclient定制对象RequestEntity和RequestBody引发的问题在处理自动提交表单的业务中往往要用到httpc

关于httpclient定制对象RequestEntity和RequestBody引发的问题
在处理自动提交表单的业务中往往要用到httpclient的poseMethod提交数据,httpclient3.1采用RequestEntity接口替代以前的RequestBody。
RequestEntity :

HttpClient client = new HttpClient();PostMethod post = new PostMethod(redirectUrl);Part[] parts = {new StringPart("user", “aaa”),new StringPart("password", "bbb")};post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));client.executeMethod(post);String result = post.getResponseBodyAsString();

RequestBody:
HttpClient client = new HttpClient();PostMethod post = new PostMethod(redirectUrl);NameValuePair[] pairs = {new NameValuePair("user", “aaa”),                        new NameValuePair("password", “bbb”)                        };post.setRequestBody(pairs);client.executeMethod(post);String result = post.getResponseBodyAsString();


在某些网站用RequestEntity方式请求有会失败,改成RequestBody就可以,可能就是这个原因。

热点排行