Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid HttpsUrlConnection eofexception
    text
    copied!<p>I have a problem where my HttpsURLConnection will throw an EOFException when i try to read any input. The code works for some network calls, but fails on others. If i try and read anything from the connection, it fails with the aforementioned error.</p> <p>Example:</p> <pre><code>urlConnect.getResponseCode() // will throw error urlConnect.getResponseMessage() // will throw error BufferedInputStream in = new BufferedInputStream(urlConnect.getInputStream()); //will throw error </code></pre> <p>Here is the stack trace for each:</p> <p>getResponse:</p> <pre><code>03-14 09:49:18.547: W/System.err(6270): java.io.EOFException 03-14 09:49:18.547: W/System.err(6270): at libcore.io.Streams.readAsciiLine(Streams.java:203) 03-14 09:49:18.547: W/System.err(6270): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573) 03-14 09:49:18.547: W/System.err(6270): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821) 03-14 09:49:18.547: W/System.err(6270): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283) 03-14 09:49:18.547: W/System.err(6270): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495) 03-14 09:49:18.547: W/System.err(6270): at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134) </code></pre> <p>BufferedInputStream: </p> <pre><code>03-14 09:39:14.077: W/System.err(5935): java.io.EOFException 03-14 09:39:14.077: W/System.err(5935): at libcore.io.Streams.readAsciiLine(Streams.java:203) 03-14 09:39:14.077: W/System.err(5935): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573) 03-14 09:39:14.077: W/System.err(5935): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821) 03-14 09:39:14.077: W/System.err(5935): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283) 03-14 09:50:46.547: W/System.err(6476): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177) 03-14 09:50:46.547: W/System.err(6476): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271) </code></pre> <p>Thank you for any help,</p> <p>Rick</p> <p><strong>EDIT</strong> I found my answer:</p> <p>This was not a well documented answer. It appears in some of the newer versions of android, there is a bug with recycled url connections. To fix this (although there may be some performance issues), I needed to add:</p> <pre><code>if (Build.VERSION.SDK != null &amp;&amp; Build.VERSION.SDK_INT &gt; 13) { urlConnect.setRequestProperty("Connection", "close"); } </code></pre> <p>Thanks!</p> <p>Rick</p>
 

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