I'm interested in just HTTP response codes (2xx, 3xx, 4xx & 5xx) for multiple sites.
My current code works well in the codename one simulator. But as app on Android the code throws EOFExceptions
for some sites. In these cases I don't get a response code back.
How can I solve this issue? What's the best and recommended way to get all these http return codes in codename one?
for (final Host h : current_hosts) {
ConnectionRequest cr = new ConnectionRequest() {
protected void readResponse(InputStream input) {
h.setHost_return_code(getResponseCode());
try {
String response = Util.readToString(input);
input.close();
} catch (IOException err) {
// do nothing
}
}
};
cr.setUrl(h.getHost_url());
cr.setHttpMethod("HEAD");
cr.setFollowRedirects(false);
cr.setReadResponseForErrors(true);
cr.setPost(false);
cr.setFailSilently(false);
cr.setSilentRetryCount(2);
cr.setTimeout(15000);
NetworkManager.getInstance().addToQueueAndWait(cr);
}
DDMS Stack Trace:
02-22 17:04:19.463: W/System.err(29698): java.io.EOFException
02-22 17:04:19.463: W/System.err(29698): at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:202)
02-22 17:04:19.463: W/System.err(29698): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:98)
02-22 17:04:19.463: W/System.err(29698): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
02-22 17:04:19.473: W/System.err(29698): at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:468)
02-22 17:04:19.473: W/System.err(29698): at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:666)
02-22 17:04:19.473: W/System.err(29698): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
02-22 17:04:19.473: W/System.err(29698): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
02-22 17:04:19.473: W/System.err(29698): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
02-22 17:04:19.473: W/System.err(29698): at com.codename1.impl.android.AndroidImplementation.getResponseCode(AndroidImplementation.java:3947)
02-22 17:04:19.473: W/System.err(29698): at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:367)
02-22 17:04:19.473: W/System.err(29698): at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:269)
02-22 17:04:19.473: W/System.err(29698): at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
02-22 17:04:19.473: W/System.err(29698): at java.lang.Thread.run(Thread.java:841)