如何通过url-request获取内容?

时间:2014-06-08 21:41:12

标签: java android

我编写的应用程序必须通过url-request显示页面内容(文本和图像)。我的任务需要手动完成,例如 WebView webView.loadUrl(url.toString()); 等变体不适用。如何以另一种方式解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试使用HTTPClient。像这样的东西。

public static InputStream getInputStreamFromUrl(String url) {
  InputStream content = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(new HttpGet(url));
    content = response.getEntity().getContent(); 
  } catch (Exception e) {
    Log.("[GET REQUEST]", "Network exception", e);
  }
    return content; //url content is here.
}