小编bad*_*ato的帖子

HTTPS REST 客户端响应

我需要从客户端进行 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");  
}  
Run Code Online (Sandbox Code Playgroud)

并按如下方式进行 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());  
}
Run Code Online (Sandbox Code Playgroud)

从 SSL/HTTPS/certs 等角度来看,这是否足够(调试除外)?我还有什么需要做的吗,比如加载密钥库或初始化 SSLContext?

java rest https

0
推荐指数
1
解决办法
5427
查看次数

标签 统计

https ×1

java ×1

rest ×1