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 }
时间: 2024-10-13 09:36:05