本帖最后由 cai123321cai 于 2011-04-05 03:28:13 编辑

解决方案 »

  1.   

    请把问题描述清楚!1:HttpClient 什么版本?
    2:代码呢?提问的智慧
    http://community.csdn.net/IndexPage/SmartQuestion.aspx
      

  2.   

    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.   

    想问一下,楼主有解决这个问题了吗?我用的是3.1版本也有这个问题。httpclient自带超时设置也无效,没办法只能自己写了超时控制。虽然解决了超时问题,但是没有解决httpclient业务失败的问题,一旦出现问题后所有的业务都是失败,重启服务器后业务恢复正常使用。线程本身并发量不是特别大,基本都是串行发起调用,通过synchronized加锁发起服务端的调用。