如何为凌空设置连接超时?

时间:2014-09-24 07:49:29

标签: android timeout android-volley

我知道凌空有一个重试策略,但我知道,这是针对套接字超时,不是为了连接超时,Apache HttpClient有setConnectionTimeout和setSoTimeout方法,有人知道我是否要为volley框架设置连接超时

2 个答案:

答案 0 :(得分:2)

您必须打开包HttpClientStack下的com.android.volley.toolbox;,然后在功能performRequest的正文中打开

的值
  HttpConnectionParams.setConnectionTimeout(httpParams, your time);
  HttpConnectionParams.setSoTimeout(httpParams, your time);
希望它有所帮助。

答案 1 :(得分:1)

如果要设置任何现有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);

参考: How to set HttpResponse timeout for Android in Java

相关问题