android default,Android DefaultHttpClient default timeout

My questions is what is default timeout for requests made with DefaultHttpClient if I didn't specify it.

So if don't have code like this

HttpParams my_httpParams = new BasicHttpParams();

HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);

HttpConnectionParams.setSoTimeout(my_httpParams, 1);

but just

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);

How long will this httpClient wait for response from server?

As far as I know the connection timeout and socket timeout for the DefaultHttpClient are both null (or zero) by default, which means that the timeouts are not used and Android application will wait theoretically forever for both the connection and socket response to complete. Therefore, it is highly recommended that to provide new connection and socket timeouts when using the DefaultHttpClient.

I did some snooping around in the source and found these two methods. So it looks like they default to 0.

/**

* Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}

* parameter. If not set, defaults to 0.

*

* @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 0.

*

* @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);

}

来源:https://stackoverflow.com/questions/18615213/android-defaulthttpclient-default-timeout

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值