请求接口发送中文出现乱码问题
StringEntity s = new StringEntity(json.toString());
s.setContentEncoding("UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
HttpResponse res = client.execute(post);
使用 setContentEncoding 不生效导致乱码,详细原因可查看源码了解
代码应改为:
StringEntity s = new StringEntity(json.toString(),"UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
HttpResponse res = client.execute(post);
json数据包含中文,再次发送post请求,问题解决