com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted:

前端 未结 2 1592
心在旅途
心在旅途 2020-12-20 13:13

I\'m using Volley library in Android in my application and when trying to make POST requests to our server I get the following error:

com.android.volley.NoC         


        
相关标签:
2条回答
  • 2020-12-20 13:50

    I found the problem after hours of searching through the Internet and project code: Inside the project I have a class named JsonToPOJORequest<T> , that extends the Volley class JsonRequest<T>. This is the class that actually makes the request for every method on the server. After analysing the code a little bit, I found a method call inside the constructor, as follows:

    setRetryPolicy(new DefaultRetryPolicy(3*DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, 0));
    

    where DefaultRetryPolicy.DEFAULT_TIMEOUT_MS is set as 2500 ms.

    Because the POST request had a lot of data, it takes more time to send the request and receive the response back from server.

    It seems that Volley didn't wait enough for the response to come and throws a TimeoutError. So, the request was made, everything goes well on the server, but the client(Android) does not wait for the server and gets an error.

    The solution was to set the Timeout parameter to be higher or 0, like this:

    setRetryPolicy(new DefaultRetryPolicy(5*DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, 0));
    setRetryPolicy(new DefaultRetryPolicy(0, 0, 0));
    

    The two questions that remain are:

    1) Why does it take so long to make the request? -> 3*2500 = 7500ms is quite a lot of time(over 7 seconds) to make a request. And this is not a server problem, since on iOS it works just fine.

    2) Why does the VolleyError look like this?

    com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted:
    

    Should be TimeoutError and not NoConnectionError.

    You can find more information about this bug here, were I also deduced the solution: Android Volley double post when have slow request

    https://groups.google.com/forum/#!topic/volley-users/8PE9dBbD6iA

    0 讨论(0)
  • 2020-12-20 14:01

    The solution is to increase the request timeout of volley by this this line of code.

    request.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    above code is settings request timeout to 10 seconds.

    0 讨论(0)
提交回复
热议问题