码迷,mamicode.com
首页 > Web开发 > 详细

httpclient请求方法

时间:2015-08-29 11:05:50      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

 1     public static String httpClientRQ(String url,Map<String,Object> paramMap,String ent){
 2         String rs = "";
 3         try{
 4             int paramLength = paramMap.size();
 5             
 6             HttpClient httpClient = new HttpClient();
 7             PostMethod post = new PostMethod(url);
 8             NameValuePair[] nps = new NameValuePair[paramLength];
 9             int index = 0;
10             for(Map.Entry<String, Object> map:paramMap.entrySet()){
11                 String key = map.getKey();
12                 Object objvalue = map.getValue();
13                 String value = "";
14                 if(objvalue!=null){
15                     value = objvalue.toString();
16                 }
17                 nps[index] = new NameValuePair();
18                 nps[index].setName(key);
19                 nps[index].setValue(value);
20                 index++;
21             }
22     
23             post.setRequestBody(nps);
24             post.getParams().setContentCharset(ent);
25             httpClient.executeMethod(post);
26             
27             rs = post.getResponseBodyAsString();
28         }catch(Exception e){
29             e.printStackTrace();
30         }
31         
32         return rs;
33     }

 

httpclient请求方法

标签:

原文地址:http://www.cnblogs.com/jinzhiming/p/4768567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!