Change Volley timeout duration

前端 未结 9 758
梦如初夏
梦如初夏 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:19

    See Request.setRetryPolicy() and the constructor for DefaultRetryPolicy, e.g.

    JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
            url, null,
            new Response.Listener() {
    
                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                }
            }, new Response.ErrorListener() {
    
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Error: " + error.getMessage());
                }
    });
    
    myRequest.setRetryPolicy(new DefaultRetryPolicy(
            MY_SOCKET_TIMEOUT_MS, 
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

提交回复
热议问题