JAVA-使用SSL证书和HTTPS的简单GET请求

JAVA-使用SSL证书和HTTPS的简单GET请求,第1张

JAVA-使用SSL证书和HTTPS的简单GET请求

我终于找到了一个很好的解决方案(无需创建自定义SSL上下文):

String getHttpResponseWithSSL(String url) throws Exception {    //default truststore parameters    System.setProperty("javax.net.ssl.trustStore", "/usr/lib/jvm/java-6-openjdk/jre/lib/securitycacerts");    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");    System.setProperty("javax.net.ssl.trustStoreType", "JKS");    //my certificate and password    System.setProperty("javax.net.ssl.keyStore", "mycert.pfx");    System.setProperty("javax.net.ssl.keyStorePassword", "mypass");    System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");    HttpClient httpclient = new HttpClient();    GetMethod method = new GetMethod();    method.setPath(url);    int statusCode = httpclient.executeMethod(method);    System.out.println("Status: " + statusCode);    method.releaseConnection();    return method.getResponseBodyAsString();}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5561626.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存