更改截击超时时间 [英] Change Volley timeout duration
本文介绍了更改截击超时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用适用于 Android 的新 Volley 框架向我的服务器发出请求.但是它在获得响应之前超时,尽管它确实响应.
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.
我尝试添加此代码:
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
在 Volley 框架的 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
的构造函数,例如
See Request.setRetryPolicy()
and the constructor for DefaultRetryPolicy
, e.g.
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屋!
查看全文