我正在尝试通过 https 访问沙盒 api:https: //api-sandbox.rabobank.nl/openapi/sandbox但发送请求时出现此错误: https ://pastebin.com/5X4h3wsu
我尝试将上述 url 中的证书添加到 jre11、jdk8、jdk7 信任库,并尝试将我的项目 jdk/jre 切换到这些版本。然而,错误并没有改变。我还尝试将其设置为 vm 选项:-Dcom.sun.net.ssl.checkRevocation=false也没有运气。当我启用时:(-Djavax.net.debug=ssl使用 java 8,选项不适用于 11)我将此输出到控制台:
https ://pastebin.com/5L7Lei8J
这是我所有的代码,这并不多,因为这个应用程序旨在通过一个最小的工作示例来测试 api。应用程序.java:
package com.thebooks;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.security.KeyStore;
@SpringBootApplication
public class Application {
static {
System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
System.setProperty("https.protocols", "TLSv1.2");
System.setProperty("javax.net.ssl.trustStore", System.getProperty("user.dir") + "/key/cert.p12");
System.setProperty("javax.net.ssl.trustStorePassword", "secret");
System.setProperty("javax.net.ssl.keyStore", System.getProperty("user.dir") + "/key/key.p12");
System.setProperty("javax.net.ssl.keyStorePassword", "secret");
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier() {
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
// TODO: CODE TO VERIFY Host
return true;
}
});
}
@Bean
public RestTemplate template() throws Exception {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
HttpClient.java:
package com.thebooks.httpclient;
import com.thebooks.enums.EScope;
import com.thebooks.providers.PropertyProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Component
public class HttpClient implements CommandLineRunner {
private String apiUrl = "https://api-sandbox.rabobank.nl/openapi/sandbox/";
private final RestTemplate template;
private PropertyProvider propProvider = new PropertyProvider();
private final String CLIENT_ID = propProvider.get("client.id");
public HttpClient(RestTemplate template) {
this.template = template;
}
@Override
public void run(String... args) throws Exception {
ResponseEntity<Object> response = template.getForEntity(
apiUrl + "oauth2/authorize?client_id=" + CLIENT_ID +
"&response_type=code&scope=" + EScope.AIS_BALANCES_READ.getValue(),
Object.class);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
}
}
我从拥有我正在尝试使用的 api 的这个网站获得了大部分代码: https ://developer-sandbox.rabobank.nl/mutual-tls 我很确定这与他们的证书不被信任有关通过我的电脑/应用程序。但是就像我说的那样,我将他们的证书添加到我拥有的所有 3 个 Java 版本的所有 3 个 cacerts 中......