首页 > 编程语言 > 详细

Spring RestTemplate调用接口乱码解决

时间:2021-04-16 12:27:43      阅读:19      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 resttemplate乱码

解决方案:

参考:Spring RestTemplate 调用天气预报接口乱码的解决

一:

        RestTemplate restTemplate = new RestTemplate(
new HttpComponentsClientHttpRequestFactory()); // 使用HttpClient,支持GZIP
restTemplate.getMessageConverters().set(1,
new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 支持中文编码

String body = restTemplate.getForObject("https://devapi.qweather.com/v7/weather/3d?location=101010100&key=7f39185f15344739b9304168b55ce56c", String.class);

 

二:

maven 依赖

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>


Connection.Response execute = Jsoup.connect("https://devapi.qweather.com/v7/weather/3d?location=101010100&key=7f39185f15344739b9304168b55ce56c").ignoreContentType(true).execute();
JSONObject jsonObject = JSONObject.parseObject(execute.body());
System.out.println(jsonObject.getString("code"));

Spring RestTemplate调用接口乱码解决

原文:https://www.cnblogs.com/liran123/p/14666069.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!