【发布时间】:2014-11-18 14:54:06
【问题描述】:
我知道 volley 有重试策略,但我知道,这是针对套接字超时,而不是针对连接超时,Apache HttpClient 有 setConnectionTimeout 和 setSoTimeout 方法,有人知道我是否想为 volley 框架设置连接超时.
【问题讨论】:
-
你检查过这个link
标签: android timeout android-volley
我知道 volley 有重试策略,但我知道,这是针对套接字超时,而不是针对连接超时,Apache HttpClient 有 setConnectionTimeout 和 setSoTimeout 方法,有人知道我是否想为 volley 框架设置连接超时.
【问题讨论】:
标签: android timeout android-volley
你必须打开包com.android.volley.toolbox;下的HttpClientStack,然后在函数体performRequest你可以改变
HttpConnectionParams.setConnectionTimeout(httpParams, your time);
HttpConnectionParams.setSoTimeout(httpParams, your time);
希望对你有帮助。
【讨论】:
如果您想设置任何现有 HTTPClient 的参数(例如 DefaultHttpClient 或 AndroidHttpClient),您可以使用setParams().
HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
//在此之后设置参数
httpClient.setParams(httpParameters);
【讨论】: