HTTPS REST ClientResponse [英] HTTPS REST ClientResponse

查看:1251
本文介绍了HTTPS REST ClientResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从客户端进行HTTPS调用。我不需要向服务器发送证书,只需要从服务器验证证书。

I need to make a HTTPS call from client. I do not need to send certificates to the server, just need to validate the certificate from the server.

我研究了这个主题,这是我的理解。你能确认一下吗?我还没有测试服务,用来验证我的代码......但仍需要满足最后期限..任何建议/输入都会有所帮助。

i researched this topic and this is my understanding. Can you please confirm? I do not have a test service yet, against which to verify my code... but still need to meet deadlines.. any advice/input will be helpful.

我把它添加到我的班级:

I added this to my class:

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通话:

And am making the HTTPS call as follows:

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吗?

Is this sufficient from SSL/HTTPS/certs etc point of view (other than debugging)? Is there anything else i need to do,like loading the keystore or initializing the SSLContext?

推荐答案

如果你使用的是自我签名证书,您可能会遇到与SSL证书验证相关的问题。 此链接讨论了此问题。

In case you are using self-signed certificate, you may face issues related to SSL Certificate validation. This link discusses this.

这篇关于HTTPS REST ClientResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆