更改排球超时持续时间 [英] Change Volley timeout duration

查看:204
本文介绍了更改排球超时持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是新的凌空框架为Android做一个请求到我的服务器。但它超时获取响应之前,虽然它不响应。

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.

我尝试添加这样code:

I tried adding this code:

HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);

HttpClientStack 凌空构架于不同的整数(50000),但它仍然超时前50秒。

in HttpClientStack of the Volley framework to a different integer (50000), but it still times out before 50 seconds.

有没有办法将超时更改为一个长整型值?

Is there a way to change the timeout to a long value?

推荐答案

请参阅 Request.setRetryPolicy()和构造 DefaultRetryPolicy ,例如:

JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
        url, null,
        new Response.Listener<JSONObject>() {

            @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));

这篇关于更改排球超时持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆