Got -1 from HttpURLConnection getResponseCode()
In my code I use
mHttpConnRespCode = mConnection.getResponseCode();
to get http response code,开发者_运维知识库 where mConnection is HttpURLConnection type.
Sometimes I got -1 as response code. Under what circumstances, mConnection.getResponseCode() returns -1?
Thanks.
You get -1 when there is no Status Code available. For example, this will happen in following scenarios,
- Response is not received yet.
- Response is not valid HTTP response.
精彩评论