Android取远程网页数据
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2014-05-15 07:34:07
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章
private String getUrlPage(String url){ String uriAPI = url; HttpGet httpRequest = new HttpGet(uriAPI); try { HttpResponse httpResponse = new DefaultHttpClient() .execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == 200) { String strResult = EntityUtils.toString(httpResponse .getEntity()); //替换掉空行 strResult = eregi_replace("(\r\n|\r|\n|\n\r)", "", strResult); return strResult; } else { return "Error Response: "+ httpResponse.getStatusLine().toString(); } } catch (ClientProtocolException e) { e.printStackTrace(); return e.getMessage().toString(); } catch (IOException e) { e.printStackTrace(); return e.getMessage().toString(); } catch (Exception e) { e.printStackTrace(); return e.getMessage().toString(); } }