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