HttpClient推送数据,对方接收到的中文数据乱码,显示问号

没改之前,中文乱码

httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
httpPost.setEntity(new StringEntity(JSONObject.toJSONString(putData)));

其实就是需要在将数据putDate转成StringEntity时,设置一个格式再发给httpPost

修改之后

httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
StringEntity stringEntity;  
stringEntity = new StringEntity((JSONObject.toJSONString(putData)),"utf-8");  
httpPost.setEntity(stringEntity);

参考了:https://blog.csdn.net/sdxushuxun/article/details/79282112 解决的问题

发篇文章免得日后自己忘记

你可能感兴趣的:(HttpClient推送数据,对方接收到的中文数据乱码,显示问号)