我有一个非常简单的spring boot项目,带有对binance api的其余调用:
@SpringBootApplication
public class BinanceServiceApplication {
public static void main(String[] args) {
SpringApplication.run(BinanceServiceApplication .class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Starting BinanceServiceApplication call...");
RestTemplate restTemplate = new RestTemplate();
String binanceUrl = "https://www.binance.com/api/v1/time";
String response = restTemplate.getForObject(binanceUrl, String.class);
System.out.println(response);
System.out.println("Terminating BinanceServiceApplication...");
System.exit(0);
};
}
}
但是我遇到以下错误:
原因:java.net.SocketException:连接重置 在java.net.SocketInputStream.read(SocketInputStream.java:210)〜[na:1.8.0_152] 在java.net.SocketInputStream.read(SocketInputStream.java:141)〜[na:1.8.0_152] 在sun.security.ssl.InputRecord.readFully(InputRecord.java:465)〜[na:1.8.0_152] 在sun.security.ssl.InputRecord.read(InputRecord.java:503)〜[na:1.8.0_152] 在sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)〜[na:1.8.0_152] 在sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)〜[na:1.8.0_152] 在sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)〜[na:1.8.0_152] 在sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)〜[na:1.8.0_152] 在sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)〜[na:1.8.0_152] 在sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)〜[na:1.8.0_152] 在sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)〜[na:1.8.0_152] 在org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)〜[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] 在org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)〜[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] 在org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)〜[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] 在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734)〜[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] ...省略了9个常见框架
同一呼叫在任何浏览器中均无问题。可能是什么原因?