Volley 设置 RetryPolicy 不起作用, 重复提交

RT, Google后有的说是 将超时时间设置为0, 但是还是会重试提交,

解决方案如下:

static HurlStack stack =  new HurlStack(){
        @Override
        protected HttpURLConnection createConnection(URL url) throws IOException {
            HttpURLConnection con = super.createConnection(url);
            //主要是这行代码, 貌似是因为HttpClient的bug
            con.setChunkedStreamingMode(0);
            return con;
        }
    };
static RequestQueue mQueue = Volley.newRequestQueue(context, stack);

//....
StringRequest req = new StringRequest(...);
req.setRetryPolicy(new DefaultRetryPolicy(20*1000, 0, 1.0f));
mQueue.add(req);

如果提交错误, 最好是取消掉该请求

mQueue.cancelAll(tag);
转载请注明出处:http://duwei.cnblogs.com/
原文地址:https://www.cnblogs.com/duwei/p/volley_retry_policy_not_working.html