Update:
String xmlList = null;
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpGet request = new HttpGet(URL);
HttpResponse response = null;
response = httpClient.execute(request);
//HttpResponse httpResponse = httpClient.execute(request);
HttpEntity httpEntity = response.getEntity();
xmlList = EntityUtils.toString(httpEntity);
}
catch (MalformedURLException e) {
xmlList = "URL: is a malformed URL";
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
xmlList = "URL: UnsupportedEncodingException";
} catch (ClientProtocolException e) {
e.printStackTrace();
xmlList = "URL: ClientProtocolException";
} catch (SocketTimeoutException e) {
e.printStackTrace();
xmlList = "URL: SocketTimeoutException";
} catch (ConnectTimeoutException e) {
e.printStackTrace();
xmlList = "URL: ConnectTimeoutException";
} catch (IOException e) {
xmlList = "URL: IOException";
e.printStackTrace();
}
finally {
httpClient.getConnectionManager().shutdown();
}
// return XML
return xmlList;
UPDATE END
i am building an app that reads data from website and i would like to know what are the exception should be check before execute the request?
the exceptions i am thinking of:
1) bad url
2) host not responding
3) time out
....
....
here is my code:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(SongsManager1.URL);
HttpResponse response = null;
response = httpClient.execute(request);
//HttpResponse httpResponse = httpClient.execute(request);
HttpEntity httpEntity = response.getEntity();
xmlList = EntityUtils.toString(httpEntity);
You could do the following checks,
You can do an network connectivity check before sending the request. Details are there in the link provided in zapl’s post.