...
This commit is contained in:
parent
f2c340d3cb
commit
0e574c7031
@ -16,14 +16,17 @@ public class WeatherDisasterWarningGrabber
|
||||
private static String QUERY_URL = "https://devapi.qweather.com/v7/warning/now?";
|
||||
private static String USER_KEY = "fe9fa8eeeb6f4301a92541eed565dd15";
|
||||
|
||||
/***
|
||||
* 从和风天气获取天气警报json字符串
|
||||
* @param cityCode 城市或区域代码
|
||||
* @return 返回警报的json字符串
|
||||
*/
|
||||
public static String getWeatherDisasterWarningJSON( String cityCode )
|
||||
{
|
||||
//拼接url字符串
|
||||
String json = "";
|
||||
String requestURL = QUERY_URL + "key=" + USER_KEY + "&location=" + cityCode;
|
||||
|
||||
//requestURL = "http://127.0.0.1:8000/ajax";
|
||||
|
||||
//链接用
|
||||
HttpURLConnection connection = null;
|
||||
URL url = null;
|
||||
@ -46,6 +49,7 @@ public class WeatherDisasterWarningGrabber
|
||||
//如果responseCode为200,说明访问成功!
|
||||
if ( connection.getResponseCode() == 200 )
|
||||
{
|
||||
//注意,和风使用了gizp压缩响应体
|
||||
inputStream = new GZIPInputStream( connection.getInputStream() );
|
||||
bufferedReader = new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user