download html source android?

Posted by mars on Stack Overflow See other posts from Stack Overflow or by mars
Published on 2010-06-18T07:21:47Z Indexed on 2010/06/18 7:53 UTC
Read the original article Hit count: 142

Filed under:
|

I'm trying to download a website source code and display it in a textbox but I seem to get an error and can't figure it out :s

 public void getHtml() throws ClientProtocolException, IOException
{
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet("http://www.spartanjava.com");
    HttpResponse response = httpClient.execute(httpGet, localContext);
    String result = "";

    BufferedReader reader = new BufferedReader(
        new InputStreamReader(
          response.getEntity().getContent()
        )
      );

    String line = null;
    while ((line = reader.readLine()) != null){
      result += line + "\n";
      Toast.makeText(activity.this, line.toString(), Toast.LENGTH_LONG).show();

    }

}

how come this doesn't work and throw an IOException?

© Stack Overflow or respective owner

Related posts about java

Related posts about android