获取国家气象局数据

获取国家气象局数据,urlPath:http://m.weather.com.cn/data/101010100.html

	public static String GetWeatherData(String urlPath) throws Exception{
		URL url = new URL(urlPath);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.connect();
		InputStream inputStream = connection.getInputStream();
		Reader reader = new InputStreamReader(inputStream, "UTF-8");
		BufferedReader bufferedReader = new BufferedReader(reader);
		String str = null;
		StringBuffer sb = new StringBuffer();
		while ((str = bufferedReader.readLine()) != null) {
			sb.append(str);
		}
		reader.close();
		connection.disconnect();
		return sb.toString();
	}	
本来想在JS中实现,可是涉及到跨域问题,整了半天没弄出来。希望有知道的能告诉我

你可能感兴趣的:(exception,String,null,url)