android - HttpUrlConnection.openConnection fails second time -


I know that this problem should be fixed with system .setProperty ("http.keepAlive", "false") ; Before OpenConnection, but he did not work before I try to work on this code, the second fails even if I try this request after less than 5 seconds, then it works . If I wait more than that, it fails again

This is my code:

  System.setProperty ("http.keepAlive", "false" ); HttpURL Connection Conn = (HttpURLConnection) mURL.openConnection (); Conn.setUseCaches (wrong); Conn.setRequestProperty ("Connection", "Keep-Alive"); Conn.setRequestProperty ("user-agent", useragent); Conn.setConnectTimeout (30000); Conn.setDoOutput (right); Conn.setDoInput (true); Consumer.sign (Conn); Input source = new input source (conn.getInputStream ());  

I get an exception on the last line:

  java.io.IOException: Write error: I / O error during system call, broken pipe w / System.err (2164): on org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl: org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativewrite (Native method) w / System.err (2164 ) on .access $ 600 (OpenSSLSocketImpl.java:55) W / System.err (2164): org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl $ SSLOutputStream.write (OpenSSLSocketImpl.java:583) w / System. to err (2164): org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.sendRequest on (: java.io.OutputStream.write (OutputStream.java:82) W / System.err ( 2164) On HttpURLConnectionImpl.java:1332) W / System.err (2164): org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal (HttpURLConnectionImpl.java:1656) W / System.err ( at 2164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest (HttpURLConne ctionImpl.java:1649) W / System.err (2164): org.apache.harmony. luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream (HttpURLConnectionImpl.java:1153) W / System.err (2164): org.apache.harmony.luni.internal.net.www.protocol.https. On HttpsURLConnectionImpl.getInputStream (HttpsURLConnectionImpl.java:253)  

Is there an idea about what's wrong here? Thanks!

connection pool used by the HttpURL connection when this connection is alive It has broken so that it tries to use the connection closed by the server. By default, Android sets KeepAlive on all connections.

System.setProperty ("http.keepAlive", "false"); is a workaround that disables KeepAlive for all connections so that you avoid the bug in the connection pool.

conn.setRequestProperty ("Connection", "Keep-Elive"); Turns on KeepAlive for this special connection, essentially what is behind System.setProperty ("http.keepAlive", "false"); does.

In addition, I always explicitly call connect because it makes it clear that you are ending your connection setup. I'm not sure this method Calling is optional or not.

  System.setProperty ("http.keepAlive", "false"); HttpURL Connection Conn = (HttpURLConnection) mURL.openConnection (); Conn.setUseCaches (wrong); Conn.setRequestProperty ("user-agent", useragent); Conn.setConnectTimeout (30000); Conn.setDoOutput (right); Conn.setDoInput (true); Consumer.sign (Conn); Conn.connect (); Input source = new input source (conn.getInputStream ());  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -