我知道截击有一个重试策略,但我知道,这是针对套接字超时,而不是针对连接超时,Apache HttpClient有setConnectionTimeout和setSoTimeout方法,有人知道我是否想为截击框架设置连接超时吗。
您必须打开包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);
请参阅:如何在Java 中为Android设置HttpResponse超时