ajax返回值中文是问号,httpclient获取返回结果中文变问号

public static String saveLog(JSONObject jsonParams) throws IOException {

logger.info("save log params : " + jsonParams.toString());

logger.debug(Instant.now().toString());

CloseableHttpClient httpClient = HttpClients.createDefault();

HttpPost httpPost = new HttpPost("http://localhost:8080/log/httpservice/saveLog");

httpPost.addHeader("Content-Type", "application/json; charset=utf-8");

httpPost.addHeader("Accept", "application/json");

// httpPost.addHeader("Accept-Language", "zh-CN");

StringEntity requestEntity = new StringEntity(jsonParams.toString(), "utf-8");

requestEntity.setContentEncoding("UTF-8");

requestEntity.setContentType("application/json; charset=utf-8");

httpPost.setEntity(requestEntity);

CloseableHttpResponse httpResponse = httpClient.execute(httpPost);

String result = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");

httpPost.releaseConnection();

httpClient.close();

logger.info("save log result : " + result);

logger.debug(Instant.now().toString());

return result;

}

功能就是调用一个服务端的http接口记录一次日志信息,经设置服务端可以获取到中文参数并处理,现在的问题是客户端程序这边获取到的返回结果中包含的中文结果反馈变成了问号。

这是服务端控制台打印结果

result = {"success":true,"message":"用户操作日志记录完成","detail":""}

这是客户端获取到的结果打印情况

save log result : {"success":true,"message":"??????????","detail":""}

服务端接收请求处理代码

@ResponseBody

@RequestMapping(value = "/saveLog", method = RequestMethod.POST)

public String saveLog(@RequestBody String requestBody) {

logger.info("requestBody = " + requestBody);

JsonObject jsonObject = new JsonParser().parse(requestBody).getAsJsonObject();

String result = this.save(jsonObject);

logger.info("result = " + result);

return result;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值