读取天气预报源码

  public static final String WEATHER_BASE_URL="http://m.weather.com.cn/data/";//详细天气

private void getWeatherInfo() throws IOException{

String url=WEATHER_BASE_URL+"101010100"+".html";

System.out.println("citycode"+cityNumber);

String weatherResult=connServerForResult(url);

System.out.println("天气来了:"+weatherResult);

parseWeatherInfo(url,weatherResult);

}

private String connServerForResult(String url) throws IOException{

HttpGet httpRequest =new HttpGet(url);

String strResult="";

HttpClient httpClient=new DefaultHttpClient();

HttpResponse httpResponse;

try {

httpResponse = httpClient.execute(httpRequest);

strResult=EntityUtils.toString(httpResponse.getEntity());

} catch (ClientProtocolException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return strResult;

}


你可能感兴趣的:(天气预报,private,public)