zoukankan      html  css  js  c++  java
  • 使 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: };

  • 相关阅读:
    筱玛的迷阵探险(折半搜索+01字典树)
    递推
    thin mission 2021 10 8
    4级 -- 阅读
    c++——小知识
    stl
    string
    ting mission 2021.9.20
    ting mission 2021.9.27
    欧拉函数
  • 原文地址:https://www.cnblogs.com/mforestlaw/p/3319838.html
Copyright © 2011-2022 走看看