HttpClient4.x中文乱码问题解决

/**
  * 发送 Post请求
  * 
  * @param url
  * @param reqXml
  * @return
  */ 
  public static String post(String url, List<NameValuePair> params) {
    String body = null;  
    try {   // 设置客户端编码   
    if (httpClient == null) {    
    httpClient = HttpClients.createDefault();   }   
   // Post请求  
    HttpPost httppost = new HttpPost(url);   
   // 设置参数 及 编码   
   httppost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));  
    // 发送请求   
    HttpResponse httpresponse = httpClient.execute(httppost);   
    // 获取返回数据   
    HttpEntity entity = httpresponse.getEntity();  
     body = EntityUtils.toString(entity);   
     if (entity != null) {   
      entity.consumeContent();   }  } 
      catch (UnsupportedEncodingException e)
       {   e.printStackTrace();  } 
       catch (ClientProtocolException e) 
       {   e.printStackTrace();  } 
       catch (ParseException e) 
       {   e.printStackTrace();  } 
       catch (IOException e)
        {   e.printStackTrace();  }  
        return body; 
        }


你可能感兴趣的:(HttpClient4.x中文乱码问题解决)