HttpPost 中文乱码。

private HttpTaskResult HttpPostRequest(String url, int reqId, String jsonBody) {
        HttpTaskResult result = new HttpTaskResult();

        HttpClient httpsClient = AppSslApplication.getHttpsClient(mContext);
        HttpPost post = new HttpPost(url);

        try {
            StringEntity params = new StringEntity(jsonBody, HTTP.UTF_8 );//HTTP.UTF_8, support Chinese and happy face. Otherwise it is messy code
            post.addHeader("content-type", "application/json");
            post.addHeader("accept", "application/json");
            post.setEntity(params);

            synchronized (httpsClient) {
                HttpResponse response = httpsClient.execute(post);
                HttpEntity entity = response.getEntity();
                result.setRetCode (response.getStatusLine().getStatusCode());
                result.setMessage (getResponseMessage(entity));
                result.setRequestId (reqId);
                response.getEntity().consumeContent();
            }

            return result;

        } catch (Exception e) {
            e.printStackTrace();
            result.setMessage("Network error: " + e.getMessage() + ", please check your connection.");
        }

        return result;
    }

使用HTTP.UTF_8 支持中文,并且支持转移符号,如笑脸等。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值