httpclient post 爬虫假死的诡异情况:求助

cai123321cai 2011-04-05 03:27:03
写了个 httpclient post 的爬虫,

header部分全部模仿ie

循环的时候会卡住不动,(对单网站循环)

也不超时也不出错,像是假死了一样,很诡异

貌似问题出在 client.executeMethod(httppost); 这行,

不知道具体哪里的问题,有人遇到过这种情况么
...全文
681 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanj007 2013-09-21
  • 打赏
  • 举报
回复
想问一下,楼主有解决这个问题了吗?我用的是3.1版本也有这个问题。httpclient自带超时设置也无效,没办法只能自己写了超时控制。虽然解决了超时问题,但是没有解决httpclient业务失败的问题,一旦出现问题后所有的业务都是失败,重启服务器后业务恢复正常使用。线程本身并发量不是特别大,基本都是串行发起调用,通过synchronized加锁发起服务端的调用。
ght369467192 2011-07-13
  • 打赏
  • 举报
回复
楼主问题解决没,我也发现了这个问题,正在纠结中..........
  • 打赏
  • 举报
回复
没遇到过。。等人解答
cai123321cai 2011-04-05
  • 打赏
  • 举报
回复
我发现手动发送 几秒后返回 404

为什么程序没反应?

也不超时,也不出错
cai123321cai 2011-04-05
  • 打赏
  • 举报
回复
坐等高手解答
cai123321cai 2011-04-05
  • 打赏
  • 举报
回复
httpclient 4.1.1


public static void main(String[] args) throws Exception {

System.setProperty( "org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog" ); //关闭日志


Protocol authhttps = new Protocol("https",
new AuthSSLProtocolSocketFactory( new URL("file:my.keystore"), "123456",
new URL("file:my.truststore"), "123456"),
443);

HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);
client.getHttpConnectionManager().getParams().setSoTimeout(3000);

client.getHostConfiguration().setHost("target.com", 443, authhttps);

/* 只能使用相对路径 */
GetMethod httpget = new GetMethod("/link");
client.executeMethod(httpget);
PostMethod httppost=new PostMethod("https://target.com");
httppost.setRequestHeader("Referer", "https://target.com");
httppost.setRequestHeader("Accept-Language", "en-US");
httppost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0)");
//httppost.setRequestHeader("Connection", "Keep-Alive");
//httppost.setRequestHeader("Cache-Control", "no-cache");
httppost.setParameter("id", id);
httppost.setParameter("link", link);
httppost.setParameter("tb", "e1s1");
httppost.setParameter("_eventId", "submit");
client.executeMethod(httppost);

String result = new String(httppost.getResponseBody());
httpget.releaseConnection(); //关闭连接
httppost.releaseConnection(); //关闭连接
}

加上循环,跑着跑着就停住不动了,跟假死一样,内存也不见变化,

上面那2个超时设置都不管用,一直卡住不动,都不会超时
  • 打赏
  • 举报
回复
请把问题描述清楚!

1:HttpClient 什么版本?
2:代码呢?

提问的智慧
http://community.csdn.net/IndexPage/SmartQuestion.aspx

81,092

社区成员

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

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