Change Volley timeout duration

前端 未结 9 799
梦如初夏
梦如初夏 2020-11-22 14:55

I use the new Volley framework for Android to do a request to my server. But it timeouts before getting the response, although it does respond.

I tried adding this

9条回答
  •  星月不相逢
    2020-11-22 15:26

    Alternative solution if all above solutions are not working for you

    By default, Volley set timeout equally for both setConnectionTimeout() and setReadTimeout() with the value from RetryPolicy. In my case, Volley throws timeout exception for large data chunk see:

    com.android.volley.toolbox.HurlStack.openConnection(). 
    

    My solution is create a class which extends HttpStack with my own setReadTimeout() policy. Then use it when creates RequestQueue as follow:

    Volley.newRequestQueue(mContext.getApplicationContext(), new MyHurlStack())
    

提交回复
热议问题