相关疑难解决方法(0)

如何使用Apache HttpClient处理无效的SSL证书?

我知道,关于这个问题有很多不同的问题和很多答案...但我无法理解......

我有:ubuntu-9.10-desktop-amd64 + NetBeans6.7.1从"关闭"安装.代表.我需要通过HTTPS连接到某个站点.为此我使用Apache的HttpClient.

从教程我读到:

"一旦正确安装了JSSE,通过SSL进行安全的HTTP通信
就像普通的HTTP通信一样简单." 还有一些例子:

HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("https://www.verisign.com/"); 
try { 
  httpclient.executeMethod(httpget);
  System.out.println(httpget.getStatusLine());
} finally {
  httpget.releaseConnection();
}
Run Code Online (Sandbox Code Playgroud)

到现在为止,我写道:

HttpClient client = new HttpClient();

HttpMethod get = new GetMethod("https://mms.nw.ru");
//get.setDoAuthentication(true);

try {
    int status = client.executeMethod(get);
    System.out.println(status);

    BufferedInputStream is = new BufferedInputStream(get.getResponseBodyAsStream());
    int r=0;byte[] buf = new byte[10];
    while((r = is.read(buf)) > 0) {
        System.out.write(buf,0,r);
    }

} catch(Exception ex) {
    ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

结果我有一组错误:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable …
Run Code Online (Sandbox Code Playgroud)

java ssl https apache-commons-httpclient

120
推荐指数
8
解决办法
29万
查看次数

标签 统计

apache-commons-httpclient ×1

https ×1

java ×1

ssl ×1