I wrote an application that hits the website daily for data. In most cases, this works just fine. However, recently I have had repeated problems when the application stopped updating data. In other words, the application works just fine, accessing the website and pulling out data ... and suddenly it will no longer be. I finally tracked it to "java.net.UnknownHostException: www.mysite.com".
The fact is that a device (this is on devices, not an emulator) can still access the Internet, so this is not a network access problem. Another thing is that this never cleans up by itself ... it will continue to give this error for DAYS. So far, the only thing I have found is fixing the phone reboot.
Unfortunately, this never happened on my phone, so I can not check it myself. I just hear about it from other people.
Is there a way to “reset” the part of the telephone network interface that resolves domain names if this is a problem?
Here is the code I use to access the website:
try {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, HTTP_TIMEOUT);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
if (entity == null) {
throw new Exception("Entity was null");
}
line = EntityUtils.toString(entity);
}
catch (ClientProtocolException cpe) {
throw new NetworkNotAvailableException("A client protocol exception occurred: " + cpe.getLocalizedMessage());
}
...and more catches below this
source
share