I’m trying to get the HTML source in a string from a web site that the user enters, the code I have so far looks like this:
public String getURLContent(String url)
{
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
ResponseHandler<String> resHandler = new BasicResponseHandler();
String page = httpClient.execute(httpGet, resHandler);
return page;
}
catch (ClientProtocolException e)
{
e.printStackTrace();
return "";
}
catch (IOException e)
{
e.printStackTrace();
return "";
}
}
Every time I try to run this I hit the second catch (IOException), which according to the documentation means the server failed to give a valid response… I am testing this with sites like “http:\www.google.com\”, so they should definitely be responding
Your code is ok. Make sure you paste full website path :
http://www. [page] . [domain]eg.:http://www.google.comAnd add this PERMISSION to
AndroidManifest.xmljust before (if it is new project):
Full example: