takayoshi
takayoshi

Reputation: 2799

loading data from site as String(Android)

I know how to load site's content in Android using WebView (webview.loadUrl("http://slashdot.org/");)

And how can I put site's content in String variable(After I'd like to parse this string to XML but this is next problen)

Upvotes: 0

Views: 836

Answers (1)

GrandMarquis
GrandMarquis

Reputation: 1913

Here is a pragmatical answer to your question:

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";
}

// Now you have the whole HTML loaded on the result variable

http://www.spartanjava.com/2009/get-a-web-page-programatically-from-android/

Upvotes: 1

Related Questions