HttpClient用HttpPost传输中文字符串乱码

// 绑定到请求 Entry
StringEntity se = new StringEntity(params.toString(),“UTF-8”);
/*

  • for Encoding Test
    System.out.println(params);
    System.out.println(se);
    System.out.println(EntityUtils.toString(se,“iso-8859-1”));
    System.out.println(EntityUtils.toString(se,“gb2312”));
    System.out.println(EntityUtils.toString(se,“gbk”));
    System.out.println(EntityUtils.toString(se,“utf-8”));
    */
    request.setEntity(se);
    // 发送请求
    HttpResponse httpResponse = new DefaultHttpClient().execute(request);
    // 得到应答的字符串,这也是一个 JSON 格式保存的数据
    String retSrc = EntityUtils.toString(httpResponse.getEntity());

通过StringEntity封好Json数据发送时候,将StringEntity se = new StringEntity(params.toString());

装好的数据中文都是?????

stringEntity.setContentEncoding(“utf-8”)------》这个没用!

后来new StringEntity中添加“UTF-8”编码设置,OK…

作者:Oliver
来源:CSDN
原文:https://blog.csdn.net/ccm_oliver/article/details/42551229
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/weixin_42868638/article/details/83302132