问题:
httpclient发送post请求,传递参数中带有中文时,服务端接收出现乱码情况
问题代码位置:
httpClient = HttpClientUtil.getHttpClient(); httpPost = new HttpPost(url); String jsonStr = jsonObject.toString(); StringEntity entity = new StringEntity(jsonStr); entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); httpPost.setEntity(entity);
解决:
设置StringEntity的字符集
解决代码:
httpClient = HttpClientUtil.getHttpClient(); httpPost = new HttpPost(url); String jsonStr = jsonObject.toString(); StringEntity entity = new StringEntity(jsonStr,"utf-8"); entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); httpPost.setEntity(entity);