Spring Boot SSL客户端 [英] Spring Boot SSL Client
问题描述
我是Spring Boot的新手.到目前为止,我很喜欢.我已经开发了一个演示SSL rest Web服务器,它可以正确处理相互X.509证书身份验证.将IE浏览器与自签名客户端&服务器证书,我已经测试了演示版休息的Web服务器是否正常工作-服务器和浏览器都已成功交换和验证彼此的证书.
I am new to Spring Boot. So far I am enjoying it. I have developed a demo SSL rest web server that correctly handles mutual X.509 certificate authentication. Using an IE browser with self signed client & server certificates, I have tested that the demo rest web server is working correctly -- both the server and browser are successfully exchanging and validating each others certificates.
我无法找到一个SSL客户端示例,该示例显示了如何包括客户端证书和发出https.有人有一个简单的Rest Client示例,它显示了如何使用我的ssl服务器吗?
I am having trouble finding an SSL client example that shows how to include the client certificate and issue the https. Anybody have a simple rest client example that shows how to consume my ssl server?
最好的问候, 史蒂夫·曼斯菲尔德
Best Regards, Steve Mansfield
推荐答案
我无法让Andy提交的上述客户端正常工作.我不断收到错误消息,说"localhost!= clientname".无论如何,我让它可以正常工作.
I could not get the above client submitted by Andy to work. I kept getting errors saying that "localhost != clientname". Anyways, I got this to work correctly.
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.methods.GetMethod;
public class SSLClient {
static
{
System.setProperty("javax.net.ssl.trustStore","c:/apachekeys/client1.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("javax.net.ssl.keyStore", "c:/apachekeys/client1.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
}
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod();
method.setURI(new URI("https://localhost:8443/restserver", false));
client.executeMethod(method);
System.out.println(method.getResponseBodyAsString());
}
}
这篇关于Spring Boot SSL客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!