httpclient如何 设置连接超时?

zwp315 2007-07-11 10:07:39
HttpClient httpclient = new HttpClient();
...全文
18412 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
nuonuo1905 2012-05-24
  • 打赏
  • 举报
回复
超时后动作怎么做
cxwujian 2012-02-09
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 winterlight09 的回复:]
引用 6 楼 sunyujia 的回复:

没注意时间顶起了这么老的帖子 晕

转眼2011了,你说的句子已经deprecated了,呵呵:
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(),1000);
[/Quote]
眨眼2012了。你的句子也不够general,呵呵
//设置连接超时时间(单位毫秒) HttpConnectionParams.setConnectionTimeout(httpPost.getParams(), 5000);
//设置读数据超时时间(单位毫秒)
HttpConnectionParams.setSoTimeout(httpPost.getParams(), 10000);
winterlight09 2011-12-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sunyujia 的回复:]

没注意时间顶起了这么老的帖子 晕
[/Quote]
转眼2011了,你说的句子已经deprecated了,呵呵:
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(),1000);
jentle 2009-01-16
  • 打赏
  • 举报
回复
HttpURLConnection是否可以设置呢
pdw2009 2008-10-17
  • 打赏
  • 举报
回复
是以千份之一秒为单位的吧
sunyujia 2008-05-03
  • 打赏
  • 举报
回复
没注意时间顶起了这么老的帖子 晕
sunyujia 2008-05-03
  • 打赏
  • 举报
回复
应该这样
client.getHttpConnectionManager().getParams().setConnectionTimeout(
11);


要看源码啊,老兄
/**
* Sets the timeout until a connection is etablished. A value of zero
* means the timeout is not used. The default value is zero.
*
* @see HttpConnection#setConnectionTimeout(int)
* @param newTimeoutInMilliseconds Timeout in milliseconds.
*
* @deprecated Use
* {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setConnectionTimeout(int)},
* {@link HttpConnectionManager#getParams()}.
*/
public synchronized void setConnectionTimeout(int newTimeoutInMilliseconds) {
this.httpConnectionManager.getParams().setConnectionTimeout(newTimeoutInMilliseconds);
}

/**
* Sets the socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the
* timeout for waiting for data. A timeout value of zero is interpreted as an
* infinite timeout.
*
* @param newTimeoutInMilliseconds Timeout in milliseconds
*
* @deprecated Use
* {@link org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int)},
* {@link HttpConnectionManager#getParams()}.
*
*/
public synchronized void setTimeout(int newTimeoutInMilliseconds) {
this.params.setSoTimeout(newTimeoutInMilliseconds);
}
kokobox 2008-05-03
  • 打赏
  • 举报
回复
lz可以到网上查一查嘛,很多的
pccastle 2008-05-02
  • 打赏
  • 举报
回复
setSoTimeOut 当然可以啦!!
zwp315 2007-07-11
  • 打赏
  • 举报
回复
难道是 HttpClient httpclient = new HttpClient();

PostMethod post = new PostMethod("");
HttpClientParams httparams=new HttpClientParams();
httparams.setSoTimeout(10);
httpclient.setParams(httparams);
zwp315 2007-07-11
  • 打赏
  • 举报
回复
httpclient.setConnectionTimeout(1);
httpclient.setTimeout(1);
上面的2个方法好像被废掉了,有没有其他方法?

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧