I found if the connection is failed,both device no wifi and connection time out, the responseCode of HttpResponse is -1, but I want to know the reason of fail, especially separate no wifi from connection timeout, is there any method to do it?
One way which you can try is to measure the time elapsed when you send the request and receive the response. The response for no internet connection is pretty instant. Timeout will usually occurs a few seconds after the request.