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

 

posted @ 2019-10-29 21:59  小叶子leavescy  阅读(9027)  评论(0编辑  收藏  举报