首页 > httpclient在jdk7遭遇connection Reset,jdk8下没有问题

httpclient在jdk7遭遇connection Reset,jdk8下没有问题

用java写的爬虫,用httpclient发送post请求,在jdk7下每次都会遇到connection reset,jdk切换成jdk8下没有问题, 引用的httpclient是4.3.6版本,为什么两种不同的jdk之下会有这样的差别,求指点一二。
我又试了一下,发现对于这个网站,只要是在jdk7的环境下,httpclient发的请求都会被connection reset,而jdk8环境下就不会。

DefaultHttpClient httpClient = HttpTools.getHttpClient("");
enableSSL(httpClient);
String testurl = "https://book.flypeach.com";
HttpGet httpGet = new HttpGet(testurl);
HttpResponse httpResponse = httpClient.execute(httpGet);
System.out.println("status:" + httpResponse.getStatusLine());


public static void enableSSL(HttpClient httpclient) {
        try {
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, new TrustManager[] { truseAllManager }, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            Scheme https = new Scheme("https", sf, 443);
            httpclient.getConnectionManager().getSchemeRegistry()
                    .register(https);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
【热门文章】
【热门文章】