开发者

Got -1 from HttpURLConnection getResponseCode()

开发者 https://www.devze.com 2023-01-02 18:36 出处:网络
In my code I use mHttpConnRespCode = mConnection.getResponseCode(); to get http response code,开发者_运维知识库 where mConnection is HttpURLConnection type.

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

精彩评论

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