I am using an Android application in that I am working on a web api. Sometimes my application connects to a web server, but sometimes it throws an exception like java.net.UnknownHostException: Host is unresolved: webservername.com:80. I get json response from api.
I use the fetch code as follows:
String queryResult = null; HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); try { request.setURI(new URI(archiveQuery)); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } //HttpResponse response = client.execute(request, new BasicResponseHandler()); try { queryResult = client.execute(request, new BasicResponseHandler()); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
source share