使 httpClient 支持中文

一个有效的方法:重载 PostMethod 的 getRequestCharSet 方法

   1: class PostChinese {
   2:     HttpClient httpClient = new HttpClient();
   3:     PostMethod postMethod = new UTF8PostMethod("http://xxxxxxxx");
   4:     NameValuePair p1 = new NameValuePair("hello", "你好");
   5:     NameValuePair p2 = new NameValuePair("world", "世界");
   6:     postMethod.setRequestBody(new NameValuePair[] {p1, p2});
   7:     try {
   8:         httpClient.executeMethod(postMethod);
   9:     } catch (HttpExeception e) {
  10:         e.printStackTrace();
  11:     } catch (IOException e) {
  12:         e.printStackTrace();
  13:     }
  14:     httpPost.releaseConnection();
  15: };
  16:  
  17: class UTF8PostMethod extends PostMethod {
  18:     public UTF8PostMethod(String url) {
  19:         super(url);
  20:     }
  21:     @Override
  22:     public String getRequestCharSet() {
  23:         return "UTF-8";
  24:     }
  25: };

原文地址:https://www.cnblogs.com/mforestlaw/p/3319838.html