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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM