When I connect to my webservice to retreive data, the phone is sometimes getting disconnected, DNS messed up, etc. Then I get an UnknownHostException
which is perfectly fine.
What I want to do is to set a timeout when looking for the hostName here:
response = httpclient.execute(httpget);
I have already set :
HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
but they don't seem to apply for HostLookUp
. Is there any way to set the timeout at host lookup?
Edit
I just found that the user cannot modify the timeout of nslookup
in this post on the hc-dev mailing list.
I will have to manually throw a timeout exception from a timer at that point.
UnknownHostException is a common error message in Java applications. This error typically indicates that there was a DNS resolution failure. If a Java application fails to get a valid DNS answer, then it might throw an UnknownHostException error.
java.net.UnknownHostException. Thrown to indicate that the IP address of a host could not be determined.
What Causes UnknownHostException. The UnknownHostException occurs when trying to connect to a remote host using its hostname, but the IP address of the host could not be determined. This usually happens because of a typo in the hostname, or because of a DNS misconfiguration or propagation delay.
A few tips to prevent the exception are: Double-check the hostname: Make sure there is no typo, and trim all whitespaces. Check the system's DNS settings: Make sure the DNS server is up and reachable, and if the hostname is new, wait for the DNS server to catch up.
First of all HttpParams httpParams = new BasicHttpParams() is depricated, use this HttpURLConnection conn = (HttpURLConnection) url.openConnection();
when your parameters size greater than 2mb then server give time out responce.
Check your params size and let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With