RequestBody 和RequestEntity使用

1 HttpClient client = new HttpClient();
2 PostMethod post = new PostMethod(redirectUrl);
3         Part[] parts = {
4                 new StringPart("user", “aaa”),
5                 new StringPart("password", "bbb")
6                 };
7         post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
8 client.executeMethod(post);
9 String result = post.getResponseBodyAsString();
1 HttpClient client = new HttpClient();
2 PostMethod post = new PostMethod(redirectUrl);
3         NameValuePair[] pairs = {
4             new NameValuePair("user", “aaa”),
5                         new NameValuePair("password", “bbb”)
6                         };
7         post.setRequestBody(pairs);
8 client.executeMethod(post);
9 String result = post.getResponseBodyAsString();

猜你喜欢

转载自www.cnblogs.com/leavescy/p/11761864.html
今日推荐