Why java.net.UnknownHostException: Host not resolved: webservername.com:80?

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(); } 
+4
source share
3 answers

I think this is the DNS problem of your server, according to your comments. Sometimes you ping, sometimes not, but does it always work in your browser? Undoubtedly, this is a problem connecting to the server.

0
source

The answer is actually very simple. You need to restart emulator . Check

0
source

Just restart adb, find adb.exe in your adt package and double click on it. Some shit will happen on the command line, and there you go, restart your emulator and it should work fine,

0
source

Source: https://habr.com/ru/post/1343590/


All Articles