开发者

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,

  1. Response is not received yet.
  2. Response is not valid HTTP response.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜