Saturday, 15 June 2013

Java - How to prevent EOFException for an empty HTTP response? -



Java - How to prevent EOFException for an empty HTTP response? -

i'm sending http request server legitimately returns blank response http response code = 200 (ok).

but causes marked line below throw eofexception:

inputstream responsestream = httpurlconnection.getinputstream(); final string contentencoding = this.connection.getcontentencoding(); if ("gzip".equalsignorecase(contentencoding)) { responsestream = new gzipinputstream(responsestream); // throws eofexception }

there may obvious way prevent can't find it. should perhaps checking connection.getcontentlength() > 0 or responsestream.available() > 0 before creating gzipinputstream? neither of these seem quite right , haven't come across similar in illustration code fragments...

should perhaps checking connection.getcontentlength() > 0

yes.

or responsestream.available() > 0

definitely not. available() == 0 isn't valid test eof, , javadoc explicitly says so.

java http exception inputstream httpurlconnection

No comments:

Post a Comment