https Java SSL Exception protocol_version

    在java代码中,使用HttpClient爬取https页面时,遇到了这个bug:javax.net.ssl.SSLException: Received fatal alert: protocol_version

      先奉上初始的代码:

复制代码
 1 /**
 2  * 
 3  */
 4 package com.tcl.mibc.weathercrawler;
 5 
 6 import org.apache.http.HttpEntity;
 7 import org.apache.http.HttpException;
 8 import org.apache.http.HttpResponse;
 9 import org.apache.http.client.HttpClient;
10 import org.apache.http.client.methods.HttpGet;
11 import org.apache.http.client.methods.HttpRequestBase;
12 import org.apache.http.impl.client.HttpClients;
13 import org.apache.http.protocol.BasicHttpContext;
14 import org.apache.http.protocol.HttpContext;
15 import org.apache.http.util.EntityUtils;
16 
17 /**
18  * @author yanzhou
19  *
20  */
21 public class PageOld {
22 
23   /**
24    * @param args
25    */
26   public static void main(String[] args) {
27     System.setProperty("javax.net.debug", "all");
28     String url = "https://www.timeanddate.com/weather/";
29     HttpClient client = HttpClients.createDefault();
30     HttpRequestBase http = new HttpGet(url);
31     HttpContext context = new BasicHttpContext();
32     try {
33       HttpResponse response = client.execute(http, context);
34       int statusCode = response.getStatusLine().getStatusCode();
35 
36       switch (statusCode) {
37         case 200:
38         case 400:// 业务异常
39           break;
40         default:
41           throw new HttpException(url + " Status Code:" + statusCode);
42       }
43 
44       HttpEntity entity = response.getEntity();
45       String reStr = EntityUtils.toString(entity);
46       System.out.println(reStr);
47     } catch (Exception e) {
48       System.out.println(e.toString());
49     }
50   }
51 
52 }
复制代码

 注:加上System.setProperty("javax.net.debug", "all");这一行是为了查看调试信息。

调试信息如下:

 

复制代码
 1 trigger seeding of SecureRandom
 2 done seeding SecureRandom
 3 16:21:43.798 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
 4 16:21:43.810 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
 5 16:21:43.810 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://www.timeanddate.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
 6 16:21:43.821 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://www.timeanddate.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
 7 16:21:43.823 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://www.timeanddate.com:443
 8 16:21:43.831 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to www.timeanddate.com/151.101.228.69:443
 9 16:21:43.831 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to www.timeanddate.com/151.101.228.69:443 with timeout 0
10 Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
11 Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
12 Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
13 Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
14 Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
15 Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
16 Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
17 Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
18 Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
19 Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
20 Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
21 Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
22 Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
23 Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
24 Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA
25 Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
26 Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
27 Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
28 Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
29 Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA
30 Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256
31 Allow unsafe renegotiation: false
32 Allow legacy hello messages: true
33 Is initial handshake: true
34 Is secure renegotiation: false
35 16:21:44.048 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled protocols: [TLSv1]
36 16:21:44.048 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_SHA, TLS_ECDH_ECDSA_WITH_RC4_128_SHA, TLS_ECDH_RSA_WITH_RC4_128_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
37 16:21:44.048 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting handshake
38 %% No cached client session
39 *** ClientHello, TLSv1
40 RandomCookie:  GMT: 1513239448 bytes = { 31, 89, 18, 56, 97, 0, 186, 78, 114, 129, 23, 167, 49, 218, 158, 250, 131, 200, 216, 78, 186, 70, 7, 144, 6, 254, 239, 98 }
41 Session ID:  {}
42 Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_SHA, TLS_ECDH_ECDSA_WITH_RC4_128_SHA, TLS_ECDH_RSA_WITH_RC4_128_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
43 Compression Methods:  { 0 }
44 Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1}
45 Extension ec_point_formats, formats: [uncompressed]
46 Extension server_name, server_name: [host_name: www.timeanddate.com]
47 ***
48 [write] MD5 and SHA1 hashes:  len = 177
49 0000: 01 00 00 AD 03 01 5A 32   34 98 1F 59 12 38 61 00  ......Z24..Y.8a.
50 0010: BA 4E 72 81 17 A7 31 DA   9E FA 83 C8 D8 4E BA 46  .Nr...1......N.F
51 0020: 07 90 06 FE EF 62 00 00   2A C0 09 C0 13 00 2F C0  .....b..*...../.
52 0030: 04 C0 0E 00 33 00 32 C0   07 C0 11 00 05 C0 02 C0  ....3.2.........
53 0040: 0C C0 08 C0 12 00 0A C0   03 C0 0D 00 16 00 13 00  ................
54 0050: 04 00 FF 01 00 00 5A 00   0A 00 34 00 32 00 17 00  ......Z...4.2...
55 0060: 01 00 03 00 13 00 15 00   06 00 07 00 09 00 0A 00  ................
56 0070: 18 00 0B 00 0C 00 19 00   0D 00 0E 00 0F 00 10 00  ................
57 0080: 11 00 02 00 12 00 04 00   05 00 14 00 08 00 16 00  ................
58 0090: 0B 00 02 01 00 00 00 00   18 00 16 00 00 13 77 77  ..............ww
59 00A0: 77 2E 74 69 6D 65 61 6E   64 64 61 74 65 2E 63 6F  w.timeanddate.co
60 00B0: 6D                                                 m
61 main, WRITE: TLSv1 Handshake, length = 177
62 [Raw write]: length = 182
63 0000: 16 03 01 00 B1 01 00 00   AD 03 01 5A 32 34 98 1F  ...........Z24..
64 0010: 59 12 38 61 00 BA 4E 72   81 17 A7 31 DA 9E FA 83  Y.8a..Nr...1....
65 0020: C8 D8 4E BA 46 07 90 06   FE EF 62 00 00 2A C0 09  ..N.F.....b..*..
66 0030: C0 13 00 2F C0 04 C0 0E   00 33 00 32 C0 07 C0 11  .../.....3.2....
67 0040: 00 05 C0 02 C0 0C C0 08   C0 12 00 0A C0 03 C0 0D  ................
68 0050: 00 16 00 13 00 04 00 FF   01 00 00 5A 00 0A 00 34  ...........Z...4
69 0060: 00 32 00 17 00 01 00 03   00 13 00 15 00 06 00 07  .2..............
70 0070: 00 09 00 0A 00 18 00 0B   00 0C 00 19 00 0D 00 0E  ................
71 0080: 00 0F 00 10 00 11 00 02   00 12 00 04 00 05 00 14  ................
72 0090: 00 08 00 16 00 0B 00 02   01 00 00 00 00 18 00 16  ................
73 00A0: 00 00 13 77 77 77 2E 74   69 6D 65 61 6E 64 64 61  ...www.timeandda
74 00B0: 74 65 2E 63 6F 6D                                  te.com
75 [Raw read]: length = 5
76 0000: 15 03 01 00 02                                     .....
77 [Raw read]: length = 2
78 0000: 02 46                                              .F
79 main, READ: TLSv1 Alert, length = 2
80 main, RECV TLSv1 ALERT:  fatal, protocol_version
81 main, called closeSocket()
82 main, handling exception: javax.net.ssl.SSLException: Received fatal alert: protocol_version
83 16:21:45.478 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
84 16:21:45.478 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
85 16:21:45.478 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://www.timeanddate.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
86 javax.net.ssl.SSLException: Received fatal alert: protocol_version
复制代码

 

重点是这一行:

*** ClientHello, TLSv1

这个表示我们使用的默认的http协议班本是:TLSv1,错误提示意思是http协议版本不正确。

于是,我按照stackoverflow上的分析,增加协议版本:"SSLv2Hello"

改版后的代码:

复制代码
 1 /**
 2  * 
 3  */
 4 package com.tcl.mibc.weathercrawler;
 5 
 6 import java.text.SimpleDateFormat;
 7 import java.util.Date;
 8 
 9 import javax.net.ssl.SSLContext;
10 
11 import org.apache.http.HttpEntity;
12 import org.apache.http.client.methods.CloseableHttpResponse;
13 import org.apache.http.client.methods.HttpPost;
14 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
15 import org.apache.http.impl.client.CloseableHttpClient;
16 import org.apache.http.impl.client.HttpClientBuilder;
17 import org.apache.http.ssl.SSLContexts;
18 import org.apache.http.util.EntityUtils;
19 
20 /**
21  * @author yanzhou
22  *
23  */
24 public class PageNew {
25 
26   /**
27    * @param args
28    */
29   public static void main(String[] args) {
30     System.setProperty("javax.net.debug", "all");
31     String url = "https://www.timeanddate.com/weather/";
32     CloseableHttpClient httpclient;
33     try {
34       SSLContext ctx = SSLContexts.createSystemDefault();
35       SSLConnectionSocketFactory fac =
36           new SSLConnectionSocketFactory(ctx, new String[] 
37               {"SSLv2Hello", "TLSv1"}, null,
38               SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
39       httpclient = HttpClientBuilder.create().setSSLSocketFactory(fac).build();
40       HttpPost httpPost = new HttpPost(url);
41       CloseableHttpResponse resp = httpclient.execute(httpPost);
42       HttpEntity entity = resp.getEntity();
43       String reStr = EntityUtils.toString(entity);
44       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
45       Date now = new Date();
46       String nowStr = sdf.format(now);
47       System.out
48           .println("======>WeatherCrawler getCurrentWeather time=" + nowStr + ", body=" + reStr);
49     } catch (Exception e) {
50       System.out.println("======>WeatherCrawler getCurrentWeather error" + e);
51     }
52   }
53 }
复制代码

调试信息:

复制代码
1 main, READ: TLSv1 Alert, length = 2
2 main, RECV TLSv1 ALERT:  fatal, protocol_version
3 main, called closeSocket()
4 main, handling exception: javax.net.ssl.SSLException: Received fatal alert: protocol_version
5 16:43:28.205 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
6 16:43:28.205 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
7 16:43:28.205 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://www.timeanddate.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
8 ======>WeatherCrawler getCurrentWeather errorjavax.net.ssl.SSLException: Received fatal alert: protocol_version
复制代码

到了这里,问题还是没有解决,报错信息跟之前一样,没有进展。

于是,我对照着下面表格,一直尝试协议的组合,直到尝试到{"SSLv2Hello", "TLSv1.2"}的组合,才抓取到页面的html代码。后来发现只用 "TLSv1.2"即可抓取到页面。

SSLContext Algorithms

The algorithm names in this section can be specified when generating an instance of SSLContext.

Algorithm Name Description
SSL Supports some version of SSL; may support other versions
SSLv2 Supports SSL version 2 or later; may support other versions
SSLv3 Supports SSL version 3; may support other versions
TLS Supports some version of TLS; may support other versions
TLSv1 Supports RFC 2246: TLS version 1.0 ; may support other versions
TLSv1.1 Supports RFC 4346: TLS version 1.1 ; may support other versions
TLSv1.2 Supports RFC 5246: TLS version 1.2 ; may support other versions
SSLv2Hello Currently, the SSLv3, TLSv1, and TLSv1.1 protocols allow you to send SSLv3, TLSv1, and TLSv1.1 hellos encapsulated in an SSLv2 format hello. For more details on the reasons for allowing this compatibility in these protocols, see Appendix E in the appropriate RFCs (previously listed).

Note that some SSL/TLS servers do not support the v2 hello format and require that client hellos conform to the SSLv3 or TLSv1 client hello formats.

The SSLv2Hello option controls the SSLv2 encapsulation. If SSLv2Hello is disabled on the client, then all outgoing messages will conform to the SSLv3/TLSv1 client hello format. If SSLv2Hello is disabled on the server, then all incoming messages must conform to the SSLv3/TLSv1 client hello format.

最终版代码:

复制代码
 1 /**
 2  * 
 3  */
 4 package com.tcl.mibc.weathercrawler;
 5 
 6 import java.text.SimpleDateFormat;
 7 import java.util.Date;
 8 
 9 import javax.net.ssl.SSLContext;
10 
11 import org.apache.http.HttpEntity;
12 import org.apache.http.client.methods.CloseableHttpResponse;
13 import org.apache.http.client.methods.HttpPost;
14 import org.apache.http.impl.client.CloseableHttpClient;
15 import org.apache.http.impl.client.HttpClientBuilder;
16 import org.apache.http.ssl.SSLContexts;
17 import org.apache.http.util.EntityUtils;
18 
19 /**
20  * @author yanzhou
21  *
22  */
23 public class PageNew {
24 
25   /**
26    * @param args
27    */
28   public static void main(String[] args) {
29     System.setProperty("javax.net.debug", "all");
30     String url = "https://www.timeanddate.com/weather/";
31     CloseableHttpClient httpclient;
32     try {
33 //      SSLContext ctx = SSLContexts.createSystemDefault();
34 //      SSLConnectionSocketFactory fac =
35 //          new SSLConnectionSocketFactory(ctx, new String[] {"TLSv1.2"}, null,
36 //              SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
37 //      httpclient = HttpClientBuilder.create().setSSLSocketFactory(fac).build();
38       SSLContext ctx = SSLContexts.custom().useProtocol("TLSv1.2").build();
39       httpclient = HttpClientBuilder.create().setSslcontext(ctx).build();
40 
41       HttpPost httpPost = new HttpPost(url);
42       CloseableHttpResponse resp = httpclient.execute(httpPost);
43       HttpEntity entity = resp.getEntity();
44       String reStr = EntityUtils.toString(entity);
45       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
46       Date now = new Date();
47       String nowStr = sdf.format(now);
48       System.out
49           .println("======>WeatherCrawler getCurrentWeather time=" + nowStr + ", body=" + reStr);
50     } catch (Exception e) {
51       System.out.println("======>WeatherCrawler getCurrentWeather error" + e);
52     }
53   }
54 }
复制代码

 

部分调试信息:

复制代码
  1 16:46:43.017 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "d[0x1e][0xb6][0xcd][0xc3][0x8e]y([0x87]$_X[0xcb]Zmv[0xa7]#[0xab][0xed][0xe6]R[0x82][0xe4][0xeb][0xac]$[0xc5][0xc6]ZH[0xc2][0xae][0xd9]MH[0x94][0x1f]B [0xdd][0xca][0x88]C3[0xf][0x9b][0xe6]aWf[0xc8][0xa5][0xef][0xb4][0xb3][0xbd][0x13][0xf1][0xbd]|3[0xb4][0x83][0x89]M[0x0][0x8a][0x2][0xbf][0xb3][0xda]mQ[0xac][0x92][0xab][0xdd][0xea][0xa8][0xe5][0x1e]+[0xdd][0xd3][0xb5][0xb4]m[0xf6]`[0xc8]`[0xec][0xda]f[0xab]c[0x1e]w[0xcd]c[0x1c]0[0xc0]J[0xb3]mv[0x80][0xbe][0x1d][0xb3][0xb][0xe3][0xd4][0x86][0xea][0x1][0xf3][0x87]=[0x89]aK)[0xb8][0xb9][\n]"
  2 16:46:43.018 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9f][0xa4]xKR[0xda][0xca][0x8f]I[0xe7]pm[0x86][0x96][0xcc][0xd0][0xcb][0xf]M[0xfb][0xf8]pM[0x86]6[0x80][0xaa]%[0xe9][0xdc];T[0xe8][0xa8][0x19][0xf9]^[0xcf]<>2[0xdb][0xf0][0xe8][0x15]t[0xbe][0xdb]4[0xbb][0xd0]a[0x4]l[[0xa2][0xc7][0xca][0xf]W[0xab][0xab][0x1]c[0xcb]k[0x9a]k5a[0xba][0x0]C[0xe9][0xb4][0xcc][0x8e][0x1c][0xc0]N~[0x0][0xdb][0x1d][0x15][0x92][0x9d]|[0xbd][0xf9][0x89]!![0x90][0x87]_[0x1e]})[0xb6][0xe4][0x84][0xb1]ZJ#[0x81][0xf])[0xc5]u[0x8f][0x14]0[0xaf]t[0x14]d][0xbe]I+e[0x1c][0xe6][0xdb][0xdc]j[0x1e][0xad][0x14][0x91]os[0xab][0xbd]2c[0xf2]ut[0x9b][0xb9][0x4][0x1f]O[0xf7][0xdc][0xe9][0xf9][0x9b][0xb7][0xa7] 0-[0xeb][0xed]yu[0xa1][0x88]TO][0xe7][0xfc]M5QS[0xfe][0xe7]?V[0xcd]j[0xaa][0xb2][0xfd][0xe5]2[0xfc]O[0x93][0xf9][0xfe][0xd7][0x8b]0[0xa8]5[0x99]4[0xff]u[0xf9][0xfd]?[0xfe][0xaf][0xea][0xdb]S[0x10][0x86][0xf]T2([0xae][0xa0][0x9f][0x19]Q9][0x88][0xe1][0xd8]w@[0x9][0xde][0xf7][0x16][0xa2][0xb8][0xba]_[0xfd][0xd2][0x13][0xd2]w[0xdf];?[0xb7][0xe][0xbe][0xaa][\n]"
  3 16:46:43.018 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[0xcd][0xcf]p[0x19][0xea][0xc3] ~[0xa5]"[0x98][0xbe][0x83]D>[0xa8]WA[0xf8][0xee][0x81]6#[0xd4][0x15]Pf[0xa4]V[0x83][0xba][0x1c][0xf3]l7vh[\r]4[0x9a][0x80][0xa4][0xeb][0x9a]![0xbb][0xa1][0xce]B[0x8d]'[0xe](5[0xfd][0xb][0x7][0xd4][0xae][0x88][0xe1][0xe2]B[0xa8][0x96]Id[0x15][0x9e][0xb5][0x91][0x1f][0xd5]`[0xd1]R[0x83]t7[0xad]n[0xb3]j[0x84][0xd1][0x1c][0x16]#U[0xb1][0xea]8[0x81][0xaf][0xfe][0xcd][0xa9]\x[0xc0][0xe4][0xc5][0x97]j^[0xa1][0xaa]*[\n]"
  4 16:46:43.018 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "U[0xb5][0xbf]7[0xe2]|[0xe4][0xd2][0x88][0x8c][0xea][0xf6][0xd4][0xa9][0xfb]q8[0xde]Oi[0xb2][0xf0]a[0x19][0xeb][0xb0][0x10][0xfa];[0xdf][0xd7][0xb6][0xe3][0xe0][0xd4][0xf8]xp[0xba][0xec][0xf8]^N[0xb9][[0xaa][0xc4][0x3][0x1e][0xb9][0xde][0xa4]6n[0xf5][0x8][0xe9]0v[0x8d][0x1f][0xe5][0xc2][0xd0]x[0xee][0xc1][0xfa][0x2][0x97][0x80]h[0xbc][0x82][0xe8][0xb3][0xd8][0xed][0x9f][0xb9]LwD[0xda][0xe5]aH[0x82]y[0xa2]i[0xa6][0x5][0xcc]@s[\r][\r]Xn[0x1b][0x11][\r][0xa6][0xcc][0xe3].[0x1f][0xc9][0x83]([\r],[0xa6][0x81][0xe5]A[0xb9][0xcf]=[0xf4][0x8e][0xe]#\[0xba][0xa5]Y_s[0x9f][0xd9]aA[0xb5][0xe]a[0xee][0xbc][0x16][0xd1][0xa9]O[0x3][0x2][0x0][0xa1][0xb5][0x80][0x12][0x7][0xed]mIC.P[0x95]6 [0xad][0xf1]z[0x99][0xc8][0xf8]>I[0xb4]l[0x89][0xb6]t[0xe8]<[0xc5]}[0xd7][0x1a][0xb1][0xed]8 [0xf6]<[0xab]L_$[0xdf][0xc]>\[0xb4][0xf9]i[0x92][0xa1][0xa8][0xe0][0x80][0xfa]<[0x88]j[0xc3][0x80][0xfe][0x14]S[0xcf]N[0xa9][0xf6]4}[0xcf][0x96][0xf9][0xbd]H[0x1b][0xae][0x12][0xed]{[0xea][0x8a]%[0xc1][0xb][0xe6]M[0xd6][0xd1]I[0xac][0x4][0xa6][0xc4][0x87][0x5]!j[0xfb][0xc6][0x1f][0xb8]G[0x8d][0x97][0xc4]_[0xd7]>[0x1e][0xb8][0xe][0xac][0x9d][0xed][0x9][0xfe][0xc6]T[0xc8]=[0xe2]&M[0xbb]L^[0x8d][0x1f]1[0x89][0xf1][0x18][0xd3][0x14][0x17][0x2][0x9a]5N[0x1b][0x1a]$[0xa5],[0xdb][0xf0]8[0x8d]).dJ)[0x2]#)[0xe2][0xa5]|3.][0xdc][0x90].[0x91]][0xcc]f[0x84]qR[0xc0][0xd7][0xd7][0xd4][0x8b][0xc4][0xda][0xc7][0xb8][0xf0]<[0xe][0xb3]J[0x96]b|[0xf1][0xe7][0xbd][0x96]e[0x9d][0x1a]Wc>3 +t[0x16][0xc9][0x17][0x1a][0xa2]0[0x98][0xcc]T[0xac][0xb6][0xe7][0xa0][0xea][0x1b][0x14][0xb][0xa9]g[0xc6]c[0xab][0x5][0x93][0xce][0xe2][0x1][0xff][0xa6][0xdc]k[0xcc][0xe4][0xf3][0xdd]q[0xaf][0xfe][0x1e][0xd7][0xa7][0xb][0xa6]%*[0xd8]S[0x1e][0x9][0x17]B3[0x3][\r][0x92][0xf7],[0xf][0xdb][[0xbb][0xf0][0xdd][[0xd2][0x8a]-'y[0xa3][0xb2],[0xae][0x6]S[0x95]o4[0xd0][0xa0][0xeb][0xbc]#[0x92]![0xdb][0xc9][0xde]X[0x84]t[0x83]I[0xef][0x0]>1[0xb5][0xf1][0x82][0xe3]5qH[0xe5][0xbd]3[0x1f][0xab][0xa8]$u[0xd8][0xdc][0x9f]W[0xfa][0xfa][0xb6]`\[0x80]\s[0xb1][0xc]N[0xde][0x8d]/0[0xea]T[0x8e]![0xf2][0x16]\:[0x1a][0x17]W[0x86]u|[0xdc][0xfd][0xe7][0xbf][0xfc]/[0xb8][0x8][0xaf][0x1b][0x17][0xae]k[0x88][0xe4][0xa1][0x1][0xac][0x85][0x6][0xd7][0xd4][0xa9]K[0xb4][0xf8]y[0x2][0xea][0xc9][0x93]k[0xa6][0x8b]S[0xc][0xbf]&[0xa3]a[0xc]\[0xb6][0xf][0xec]uJ[0x98][0x87][0xcf][0xc][0x8b][0xf5]x:b[0x4]Kx[0xf1][0xfd][0xd3][0x17][0xba][0xce][\r])u[0x6][0xc4][0x9e][0xa4]3?y[0x15]@[0xfc][0x19][0xca][[0x14][0xb3][0xb7]n[0xa4][0x12][0xd6][0xf6]C[0x98][0xe6][0xd1]&#K[0xb9][0x95][0xf2][0xad][0x8c]$[0xdb][0x94][0x13]D[0xb]P[0x6]H[0x9c]N[0xde]'[0x8b][0xf][0x1b][0xf3][0xf9][0x1][0xbb]&[0xb][0x96]v)[0xdf]Vr[0x84][0xc]/[0xcf][0xf0][0x93]TW[0xf2]M[0x2]$;>Z[0xb8]?}[0xf4]$[0x11][0xb1][0x95]D[0xfe][0x9d]x[0xc0]S*[0xa9][0xd5]lh[0xa7][0xd3]e[0xf][0xc5][0xfe][0x80];s[0xf8][0x80]5[0xf5][0xff]?[0x94]l[0xc5]|[0x3][0xf8][0x0][0x0]"
  5 16:46:43.018 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://www.timeanddate.com:443] can be kept alive indefinitely
  6 16:46:43.018 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://www.timeanddate.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
  7 ======>WeatherCrawler getCurrentWeather time=2017-12-14 04:46:43, body=World Temperatures — Weather Around The World
 10 
 11 
 12 
 67 
70
73
Home   Weather
74 75 76 77

World Temperatures — Weather Around The World

78
79

Local Time and Weather Around the World

Accra星期四 08:46Fog. Warm.26 °CKolkata星期四 14:16Haze. Warm.28 °C
Addis Ababa星期四 11:46Smoke. Mild.19 °CKuala Lumpur星期四 16:46Broken clouds. Hot.33 °C
Adelaide *星期四 19:16Passing clouds. Mild.21 °CKuwait City星期四 11:46Sunny. Mild.20 °C
Algiers星期四 09:46Clear. Refreshingly cool.13 °CKyiv星期四 10:46Fog. Chilly.1 °C
Almaty星期四 14:46Ice fog. Cold.-5 °CLa Paz星期四 04:46Passing clouds. Chilly.4 °C
Amman星期四 10:46Scattered clouds. Cool.14 °CLagos星期四 09:46Fog. Warm.25 °C
Amsterdam星期四 09:46Sprinkles. Broken clouds. Chilly.4 °CLahore星期四 13:46Scattered clouds. Cool.13 °C
Anadyr星期四 20:46Passing clouds. Frigid.-19 °CLas Vegas星期四 00:46Passing clouds. Cool.11 °C
Anchorage星期三 23:46Clear. Chilly.2 °CLima星期四 03:46Passing clouds. Mild.19 °C
Ankara星期四 11:46Fog. Chilly.1 °CLisbon星期四 08:46Drizzle. Fog. Cool.14 °C
Antananarivo星期四 11:46Passing clouds. Warm.27 °CLondon星期四 08:46Passing clouds. Chilly.4 °C
Asuncion *星期四 05:46Clear. Warm.26 °CLos Angeles星期四 00:46Clear. Cool.12 °C
Athens星期四 10:46Passing clouds. Cool.14 °CMadrid星期四 09:46Fog. Quite cool.7 °C
Atlanta星期四 03:46Clear. Chilly.3 °CManila星期四 16:46Partly sunny. Warm.30 °C
Auckland *星期四 21:46Passing clouds. Mild.21 °CMelbourne *星期四 19:46Partly sunny. Mild.20 °C
Baghdad星期四 11:46Clear. Quite cool.4 °CMexico City星期四 02:46Clear. Cool.9 °C
Bangalore星期四 14:16Clear. Warm.27 °CMiami星期四 03:46Passing clouds. Cool.11 °C
Bangkok星期四 15:46Fog. Hot.32 °CMinneapolis星期四 02:46Passing clouds. Cold.-8 °C
Barcelona星期四 09:46Passing clouds. Cool.9 °CMinsk星期四 11:46Ice fog. Chilly.-2 °C
Beijing星期四 16:46Overcast. Chilly.0 °CMontevideo星期四 05:46Clear. Mild.19 °C
Beirut星期四 10:46Passing clouds. Mild.20 °CMontréal星期四 03:46Passing clouds. Frigid.-17 °C
Belgrade星期四 09:46Passing clouds. Chilly.1 °CMoscow星期四 11:46Fog. Chilly.1 °C
Berlin星期四 09:46Broken clouds. Chilly.4 °CMumbai星期四 14:16Clear. Warm.27 °C
Bogota星期四 03:46Passing clouds. Cool.11 °CNairobi星期四 11:46Partly sunny. Mild.20 °C
Boston星期四 03:46Mostly cloudy. Cold.-5 °CNassau星期四 03:46Passing clouds. Cool.11 °C
Brasilia *星期四 06:46Light rain. Passing clouds. Cool.8 °CNew Delhi星期四 14:16Scattered clouds. Cool.16 °C
Brisbane星期四 18:46Passing clouds. Warm.25 °CNew Orleans星期四 02:46Clear. Cool.11 °C
Brussels星期四 09:46Partly sunny. Chilly.4 °CNew York星期四 03:46Light snow. Ice fog. Chilly.-4 °C
Bucharest星期四 10:46Low clouds. Quite cool.5 °COslo星期四 09:46Freezing rain. Overcast. Chilly.-1 °C
Budapest星期四 09:46Fog. Chilly.1 °COttawa星期四 03:46Passing clouds. Frigid.-19 °C
Buenos Aires星期四 05:46Passing clouds. Mild.20 °CParis星期四 09:46Partly cloudy. Chilly.4 °C
Cairo星期四 10:46Haze. Mild.18 °CPerth星期四 16:46Sunny. Warm.26 °C
Calgary星期四 01:46Clear. Chilly.-1 °CPhiladelphia星期四 03:46Mostly cloudy. Chilly.-2 °C
Canberra *星期四 19:46Sprinkles. Clear. Warm.25 °CPhoenix星期四 01:46Clear. Cool.11 °C
Cape Town星期四 10:46Passing clouds. Mild.19 °CPrague星期四 09:46Scattered clouds. Chilly.4 °C
Caracas星期四 04:46Passing clouds. Mild.23 °CReykjavik星期四 08:46Passing clouds. Chilly.-3 °C
Casablanca星期四 08:46Sunny. Cool.8 °CRio de Janeiro *星期四 06:46Passing clouds. Mild.23 °C
Chicago星期四 02:46Light snow. Mostly cloudy. Chilly.-3 °CRiyadh星期四 11:46Sunny. Mild.20 °C
Copenhagen星期四 09:46Light rain. Partly sunny. Chilly.2 °CRome星期四 09:46Partly sunny. Cool.13 °C
Dallas星期四 02:46Passing clouds. Quite cool.6 °CSalt Lake City星期四 01:46Ice fog. Chilly.-3 °C
Dar es Salaam星期四 11:46Partly sunny. Warm.30 °CSan Francisco星期四 00:46Passing clouds. Cool.10 °C
Darwin星期四 18:16Partly sunny. Hot.32 °CSan Juan星期四 04:46Passing clouds. Warm.25 °C
Denver星期四 01:46Light snow. Mostly cloudy. Chilly.0 °CSan Salvador星期四 02:46Clear. Mild.18 °C
Detroit星期四 03:46Overcast. Cold.-6 °CSantiago *星期四 05:46Passing clouds. Cool.16 °C
Dhaka星期四 14:46Sunny. Warm.27 °CSanto Domingo星期四 04:46Passing clouds. Warm.25 °C
Doha星期四 11:46Passing clouds. Mild.23 °CSão Paulo *星期四 06:46Mostly cloudy. Mild.18 °C
Dubai星期四 12:46Passing clouds. Pleasantly warm.25 °CSeattle星期四 00:46Clear. Quite cool.5 °C
Dublin星期四 08:46Passing clouds. Chilly.2 °CSeoul星期四 17:46Sunny. Cold.-4 °C
Edmonton星期四 01:46Chilly.-1 °CShanghai星期四 16:46Light rain. Partly sunny. Cool.8 °C
Frankfurt星期四 09:46Scattered clouds. Quite cool.5 °CSingapore星期四 16:46Partly sunny. Warm.31 °C
Guatemala City星期四 02:46Overcast. Cool.12 °CSofia星期四 10:46Partly sunny. Quite cool.5 °C
Halifax星期四 04:46Snow flurries. Passing clouds. Cold.-4 °CSt. John's星期四 05:16Mostly cloudy. Cool.8 °C
Hanoi星期四 15:46Broken clouds. Mild.17 °CStockholm星期四 09:46Light rain. Mostly cloudy. Chilly.3 °C
Harare星期四 10:46Partly sunny. Warm.25 °CSuva *星期四 21:46Sprinkles. Overcast. Mild.24 °C
Havana星期四 03:46Passing clouds. Cool.12 °CSydney *星期四 19:46Thundershowers. Partly sunny. Warm.29 °C
Helsinki星期四 10:46Partly sunny. Chilly.0 °CTaipei星期四 16:46Broken clouds. Mild.20 °C
Hong Kong星期四 16:46Passing clouds. Mild.22 °CTallinn星期四 10:46Scattered clouds. Chilly.-1 °C
Honolulu星期三 22:46Partly cloudy. Mild.22 °CTashkent星期四 13:46Ice fog. Chilly.-2 °C
Houston星期四 02:46Passing clouds. Cool.9 °CTegucigalpa星期四 02:46Passing clouds. Cool.13 °C
Indianapolis星期四 03:46Overcast. Chilly.-1 °CTehran星期四 12:16Sunny. Quite cool.7 °C
Islamabad星期四 13:46Partly sunny. Refreshingly cool.15 °CTokyo星期四 17:46Passing clouds. Cool.9 °C
Istanbul星期四 11:46Passing clouds. Cool.14 °CToronto星期四 03:46Partly cloudy. Cold.-12 °C
Jakarta星期四 15:46Overcast. Warm.28 °CVancouver星期四 00:46Partly cloudy. Quite cool.5 °C
Jerusalem星期四 10:46Cool.13 °CVienna星期四 09:46Overcast. Chilly.2 °C
Johannesburg星期四 10:46Passing clouds. Mild.21 °CWarsaw星期四 09:46Light snow. Partly sunny. Chilly.0 °C
Karachi星期四 13:46Clear. Mild.23 °CWashington DC星期四 03:46Passing clouds. Chilly.2 °C
Kathmandu星期四 14:31Passing clouds. Mild.21 °CWinnipeg星期四 02:46Cold.-10 °C
Khartoum星期四 10:46Sunny. Pleasantly warm.27 °CYangon星期四 15:16Clear. Hot.33 °C
Kingston星期四 03:46Passing clouds. Warm.25 °CZagreb星期四 09:46Passing clouds. Chilly.2 °C
Kinshasa星期四 09:46Thunderstorms. Low clouds. Mild.22 °CZürich星期四 09:46Chilly.0 °C
Kiritimati星期四 22:46Passing clouds. Warm.26 °C

* = Adjusted for DST or summer time (11 places).

星期三 = 星期三, 13 十二月 2017 (2 places).
星期四 = 星期四, 14 十二月 2017 (139 places).

UTC (GMT/Zulu)-time: 星期四, 14 十二月 2017, 08:46:42

UTC is Coordinated Universal Time, GMT is Greenwich Mean Time.

Advertising
89
90
91
92 108 109 110 111 112
复制代码

到了这里,问题才算解决。

分析:TLSv1.2是http默认协议的增强版,增加了一些安全方面的特性:保护传输数据安全,防止被窃取和篡改。

 参考链接:

1)stackoverflow上的分析:

https://stackoverflow.com/questions/31684855/java-ssl-exception-protocol-version-when-trying-to-use-httpclient-to-log-into-a

2)标准的http协议名称:

https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#SSLContext

 

3)https站点强制通信协议TLSv1.2

 

 http://m.blog.csdn.net/fred_lzy/article/details/74178023

 

 

 

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案

这个是jdk导致的,jdk里面有一个jce的包,安全性机制导致的访问https会报错,官网上有替代的jar包,换掉就好了

目录 %JAVA_HOME%\jre\lib\security里的local_policy.jar,US_export_policy.jar

JDK7 http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

JDK8 http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

https://www.cnblogs.com/1995hxt/p/6185399.html

 https://blog.csdn.net/dzy_001/article/details/81012959

转载于:https://www.cnblogs.com/softidea/p/10662591.html

你可能感兴趣的:(https Java SSL Exception protocol_version)