Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange HttpResponse in Android
    primarykey
    data
    text
    <p>I am having an unusual problem regarding the following code in an android application.</p> <pre><code>public InputStream retrieveStream(String url) { HttpGet request = new HttpGet(url); HttpParams httpParams = new BasicHttpParams(); int some_reasonable_timeout = (int) (10 * DateUtils.SECOND_IN_MILLIS); HttpConnectionParams.setConnectionTimeout(httpParams, some_reasonable_timeout); HttpConnectionParams.setSoTimeout(httpParams, some_reasonable_timeout); HttpClient client = new DefaultHttpClient(httpParams); try { HttpResponse response = client.execute(request); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK){ HttpEntity getResponseEntity = response.getEntity(); return getResponseEntity.getContent(); } else { Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url); return null; } } catch (ClientProtocolException e) { Log.e("Methods", "HTTP Error", e); return null; } catch (IOException e) { Log.e("Methods", "Connection Error", e); return null; } } </code></pre> <p>Within the application I attempt to connect to a localhost.(In an AsyncTask)</p> <pre><code>InputStream source = retrieveStream("http://10.0.2.2:27080/testdb/_hello") </code></pre> <p>When running on the emulator, this code works fine and if the localhost is down, "source" is returned as null as expected. Similarly when running the code on a mobile device (HTC Nexus One, Android Version 2.2), the code reports "source" as null as expected. However when running the same APK on another mobile device (Samsung Galaxy S2, Android Version 4.0.3, samsung release), the status code returned is given as HttpStatus.SC_OK, even though it couldnt possibly be connecting to the localhost. Has anyone encountered a similar problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload