原来部分代码如下:
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
try {
StringEntity s = new StringEntity(jsonStr);
s.setContentEncoding("UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
CloseableHttpResponse res = client.execute(post);

修改如下,在初始化StringEntity时指定UTF-8:
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
try {
StringEntity s = new StringEntity(jsonStr,"UTF-8");
s.setContentEncoding("UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
CloseableHttpResponse res = client.execute(post);

相关文章:

  • 2021-05-06
  • 2021-05-27
  • 2021-08-23
  • 2021-12-29
  • 2021-07-30
  • 2022-01-17
  • 2021-07-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-12-21
  • 2022-01-20
  • 2021-06-02
相关资源
相似解决方案