android - "unexpected end of stream" thrown during NetHttpRequest.execute() when uploading file -


this has been asked in couple questions i've yet see real answer. i've got android code executes nethttprequest post image server, fails so:

unexpected end of stream java.io.ioexception: unexpected end of stream     @ libcore.net.http.fixedlengthoutputstream.close(fixedlengthoutputstream.java:58)     @ com.google.api.client.http.javanet.nethttprequest.execute(nethttprequest.java:84)     @ com.google.api.client.http.httprequest.execute(httprequest.java:1009)     @ com.test.myactivity$imageuploadtask.doinbackground(myactivity.java:870)     @ com.test.myactivity$imageuploadtask.doinbackground(myactivity.java:1)     @ android.os.asynctask$2.call(asynctask.java:287)     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305)     @ java.util.concurrent.futuretask.run(futuretask.java:137)     @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230)      @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569)     @ java.lang.thread.run(thread.java:856) 

i don't it... why fail this? given backtrace makes me believe must have http library prematurely closing connection, can't determine why. of related questions have same problem (e.g. uploading jpeg google drive android app "unexpected end of stream", ) except in every case question goes unanswered or asker finds strange workaround seems solve them (although getting lucky).

my upload code isn't special either, asynctask creates httprequest , executes it. works fine of time, other times fails inexplicably. gives?

ok, figured out.

after more debugging able eliminate lot of variables , convinced myself bug had exist in core http library. googling found people referencing bugs in android's implementation of http keep alive (https://code.google.com/p/googleappengine/issues/detail?id=9291, weird eofexception on galaxy nexus, etc.).

so added code activity:

system.setproperty("http.keepalive", "false"); 

and fixed problem. annoying workaround, works.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -