关于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();
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();