以下是我使用
的代码UriComponentsBuilder builder = UriComponentsBuilder
.newInstance()
.host(HOST)
.scheme("https")
.path("/query");
builder.queryParam("function", "TIME_SERIES_INTRADAY");
builder.queryParam("symbol", exchange.isEmpty() ? ticker : (exchange + ":" + ticker));
builder.queryParam("interval", "30min");
builder.queryParam("apikey", System.getenv("LEO_ALPHA_VANTAGE_KEY_12"));
try {
URL uri = new URL(builder.build().toUriString());
System.setProperty("https.protocols", "TLSv1.2");
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
导致此异常,这是在启用debug = all并且我也启用了tls1.2
main, WRITE: TLSv1.2 Handshake, length = 237
[Raw write]: length = 242
0000: 16 03 03 00 ED 01 00 00 E9 03 03 5A 8B 6B 97 B1 ...........Z.k..
0010: 9D 19 5F 18 2A F5 32 F0 32 FE 29 64 31 0B A2 8C .._.*.2.2.)d1...
0020: A6 57 80 79 AE F7 7F D3 12 40 02 00 00 64 C0 24 .W.y.....@...d.$
0030: C0 28 00 3D C0 26 C0 2A 00 6B 00 6A C0 0A C0 14 .(.=.&.*.k.j....
0040: 00 35 C0 05 C0 0F 00 39 00 38 C0 23 C0 27 00 3C .5.....9.8.#.'.<
0050: C0 25 C0 29 00 67 00 40 C0 09 C0 13 00 2F C0 04 .%.).g.@...../..
0060: C0 0E 00 33 00 32 C0 2C C0 2B C0 30 00 9D C0 2E ...3.2.,.+.0....
0070: C0 32 00 9F 00 A3 C0 2F 00 9C C0 2D C0 31 00 9E .2...../...-.1..
0080: 00 A2 C0 08 C0 12 00 0A C0 03 C0 0D 00 16 00 13 ................
0090: 00 FF 01 00 00 5C 00 0A 00 16 00 14 00 17 00 18 .....\..........
00A0: 00 19 00 09 00 0A 00 0B 00 0C 00 0D 00 0E 00 16 ................
00B0: 00 0B 00 02 01 00 00 0D 00 1C 00 1A 06 03 06 01 ................
00C0: 05 03 05 01 04 03 04 01 04 02 03 03 03 01 03 02 ................
00D0: 02 03 02 01 02 02 00 17 00 00 00 00 00 14 00 12 ................
00E0: 00 00 0F 61 6C 70 68 61 76 61 6E 74 61 67 65 2E ...alphavantage.
00F0: 63 6F co
main, received EOFException: error
main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
main, SEND TLSv1.2 ALERT: fatal, description = handshake_failure
main, WRITE: TLSv1.2 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 03 00 02 02 28 ......(
main, called closeSocket()
Exception in thread "main" java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at com.compass.leo.util.AlphaVantage.getStockTimeSeries(AlphaVantage.java:128)
at com.compass.leo.util.AlphaVantage.getStockTimeSeries(AlphaVantage.java:84)
at com.compass.leo.LeoApplication.main(LeoApplication.java:42)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1002)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
at
com.compass.leo.util.AlphaVantage.getStockTimeSeries(AlphaVantage.java:116)
... 2 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
... 12 more
我想知道这里会出现什么错误?我可以通过邮递员轻松拨打本网站的电话,
这可能是什么问题?
答案 0 :(得分:0)
一旦我遇到了类似的问题,我花了2天的时间才弄明白。我不知道这是不是你的情况,但它可能值得一试。
我在一台服务器上运行该应用程序,该服务器有一个阻止该请求的代理。当我发送https://my-server/my-service请求时,它会从公司返回一个HTTP页面,上面写着“阻止IT内容”。此HTTP页面无法完成握手,因为它不是HTTPS页面。
解决方案是让IT将服务器上的域列入白名单。