在resttemplate.exchange上的SocketException连接重置错误

时间:2019-06-18 14:19:57

标签: java spring networking resttemplate

当我尝试向Apple api URL发出请求时,我开始出现ConnectionReset错误。

我没有进行代码更改,但突然开始出现错误。当我使用curl命令调用url时,我可以得到答案,但是当我从代码中调用它时,它将引发以下异常。

什么可能导致此错误?

Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api-applecareconnect.apple.com/enroll-service/1.0/show-order-details": Connection reset; nested exception is java.net.SocketException: Connection reset
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:534)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:482)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:430)


Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
    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 org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:82)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:50)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:519)
    ... 122 more

2 个答案:

答案 0 :(得分:0)

请在这里I/O error on POST request for... java.net.SocketException: Connection reset

查看我的答案

这似乎是相同的问题。 @EspringDev实际上指向正确的方向。 按照Apple的规定,它们支持从1.0到1.3的所有版本。但是您使用的API可能有SSL/TLS security policy。我希望这能解决问题。

答案 1 :(得分:0)

事实证明,问题出在没有我们的信息的情况下更改了防火墙策略。它阻止了对Apple服务器的访问。