httpclient post 爬虫假死的诡异情况:求助 本帖最后由 cai123321cai 于 2011-04-05 03:28:13 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请把问题描述清楚!1:HttpClient 什么版本?2:代码呢?提问的智慧http://community.csdn.net/IndexPage/SmartQuestion.aspx 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个超时设置都不管用,一直卡住不动,都不会超时 想问一下,楼主有解决这个问题了吗?我用的是3.1版本也有这个问题。httpclient自带超时设置也无效,没办法只能自己写了超时控制。虽然解决了超时问题,但是没有解决httpclient业务失败的问题,一旦出现问题后所有的业务都是失败,重启服务器后业务恢复正常使用。线程本身并发量不是特别大,基本都是串行发起调用,通过synchronized加锁发起服务端的调用。 帮帮忙啊~ 关于DOUBLE类型不显示科学计数法!! 求:JSP完全手册 电子书 webservice 能传java的对象吗?例如sql.Date List等? web 开发最常用的包是那些 高分求助转码问题 在sqlserver数据库中,我读取数据时是成功,但是,解析确实错误? 关于JSP乱吗提问 [求助]我做的分页程序有问题请高手帮帮我! 高分在线求助!!!如何将网页上的内容通过点击网页上的"SAVE"按钮打开保存对话框并存为Excel文件??? js动态合并table在线等。。。。。 JSP连oracle无法获取完整数据
2:代码呢?提问的智慧
http://community.csdn.net/IndexPage/SmartQuestion.aspx
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个超时设置都不管用,一直卡住不动,都不会超时