Android DefaultHttpClient默认超时
我的问题是,如果我没有指定,使用DefaultHttpClient发出的请求的默认超时是多少 所以如果你没有这样的代码Android DefaultHttpClient默认超时,android,http,Android,Http,我的问题是,如果我没有指定,使用DefaultHttpClient发出的请求的默认超时是多少 所以如果你没有这样的代码 HttpParams my_httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000); HttpConnectionParams.setSoTimeout(my_httpParams, 1); 但只是 HttpParams params
HttpParams my_httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);
HttpConnectionParams.setSoTimeout(my_httpParams, 1);
但只是
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setContentCharset(params,
HTTP.DEFAULT_CONTENT_CHARSET);
ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
schemeRegistry);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
return new DefaultHttpClient(cm, params);
这个httpClient将等待服务器响应多长时间?据我所知,默认httpClient的连接超时和套接字超时默认都为null(或零),这意味着不使用超时,Android应用程序将永远等待连接和套接字响应完成。因此,强烈建议在使用DefaultHttpClient时提供新的连接和套接字超时。我在源代码中进行了一些搜索,找到了这两种方法。所以看起来它们默认为0
/**
* Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
* parameter. If not set, defaults to <code>0</code>.
*
* @param params HTTP parameters.
* @return connect timeout.
*/
public static int getConnectionTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
return params.getIntParameter
(CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
}
/**
* Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
* If not set, defaults to <code>0</code>.
*
* @param params HTTP parameters.
* @return SO_TIMEOUT.
*/
public static int getSoTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
}
正如在HttpConnectionParams.getConnectionTimeout和HttpConnectionParams.getSoTimeout的文档中所述,默认值为0,并被解释为没有超时。我理解正确了吗?可能是