首先
说一下我们用的api的url,可以直接在浏览器上输入查询,但是会出现乱码问题。
http://wthrcdn.etouch.cn/weather_mini?city=海淀
这里我们可以使用线上的测试工具。
https://www.sojson.com/convert/word2spell.html
注意,这里是get请求UTF-8,输入地址,发送请求就可以查看天气了。
- java代码部分
第一步,加入依赖 (pom文件)
<!--http必要-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<a