【发布时间】:2025-03-31 01:40:01
【问题描述】:
我需要从客户端进行 HTTPS 调用。我不需要向服务器发送证书,只需要验证来自服务器的证书。
我研究了这个话题,这是我的理解。你能确认一下吗?我还没有测试服务,可以用来验证我的代码……但仍需要按时完成……任何建议/输入都会有所帮助。
我将此添加到我的班级:
private static String appKeyFile = "/project/src/security/cert_file.jck";
private static String key = "password";
static {
System.setProperty("javax.net.ssl.keyStore", appKeyFile);
System.setProperty("javax.net.ssl.keyStorePassword",key);
System.setProperty("javax.net.ssl.keyStoreType","JCEKS");
}
并按如下方式进行 HTTPS 调用:
config = new DefaultClientConfig();
client = Client.create(config);
service = client.resource(UriBuilder.fromUri("https://localhost:8081/TestService").build());
clientResponse = service.path("rs").path("test").path("getCustomerDetail")
.accept(MediaType.APPLICATION_XML)
.post(ClientResponse.class, customerRequestType);
if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) {
custResponseType = clientResponse.getEntity(CustResponseType.class);
System.out.println("First Name" +
custResponseType.getFirstName());
}
从 SSL/HTTPS/certs 等角度来看,这是否足够(调试除外)?还有什么我需要做的吗,比如加载密钥库或初始化 SSLContext?
【问题讨论】:
-
您使用的是哪个面向 REST 的库?