问题描述
今天想尝试使用今日头条的城市接口
https://www.toutiao.com/stream/widget/local_weather/city/
(获取到中国所有的省、城市)。浏览器直接访问的结果如下
用RestTemplate直接访问这个地址,代码如下
RestTemplate restTemplate = new RestTemplate();
//消息头的ContentType
MediaType type = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE);
//请求头
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(type);
//请求体
String httpBody = null;
HttpEntity<String> httpEntity = new HttpEntity<>(httpBody,httpHeaders);
URI uri = URI.create(url+"?"+params);
//发起请求
ResponseEntity<String> resp = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class);
return resp.