Android Volley double post when have slow request

后端 未结 18 2699
生来不讨喜
生来不讨喜 2020-11-28 04:06

I have a problem with Volley POST request on slow network. Everytime I see BasicNetwork.logSlowRequests in my LogCat, my POST request is executed twice or more

18条回答
  •  孤城傲影
    2020-11-28 04:36

    I am able to solve this issue by two ways.

    First is changed the RetryPolicy. Simply set the timeout value to double of the default timeout. Worked fine. You can also try other values.

    request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    Another way is by setting connection.setChunkedStreamingMode(0); in openConnection method HurlStack class.

    I am creating my RequestQueue like this requestQueue = Volley.newRequestQueue(context, new HurlStack());

    Hope it helps :)

提交回复
热议问题