https://blog.csdn.net/weixin_38959210/article/details/83515783
首先进上面这个链接的文档里面,获取到JAVA调用HTTP接口的方法。
我们用的这个http接口获取天气情况"http://t.weather.sojson.com/api/weather/city/101170301",后面的"101170301"为城市编号。
各城市编号连接下载地址"https://download.csdn.net/download/weixin_38959210/10793554";
@RequestMapping(value = "/tianqi.do")
public JSONObject tianqi(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("UTF-8");
System.out.println("/tianqi.do打印出的东西:"+cn.temptation.web.tianqi.sendGet("http://t.weather.sojson.com/api/weather/city/101170301"));
return (JSONObject) JSON.parse(cn.temptation.web.tianqi.sendGet("http://t.weather.sojson.com/api/weather/city/101170301"));