我想ping一下一个https的请求,但是用httpclinet请求报错! 
        HttpClient client = new HttpClient();
        client.setConnectionTimeout(10 * 1000);
        client.setTimeout(10 * 1000);
        //一个HTTPS的地址
        PostMethod post = new PostMethod("https://...........");        try {
            int status = client.executeMethod(post);            if (status != Constants.HTTP_STATUS_OK) {
                return SERVICE_CLOSE;
            }            return SERVICE_OK;
        } catch (SocketTimeoutException timeOut) {
            timeOut.printStackTrace();
            return SERVICE_TIME_OUT;
        } catch (Exception e) {
            e.printStackTrace();
            return SERVICE_CLOSE;
        }
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath请问大家https的请求怎么解决啊?这种方法只能请求http的!!

解决方案 »

  1.   

    网上找的,希望对你有帮助:httpclient完全支持ssl连接方式。通常,如果不需要进行客户端认证和服务器端认证的ssl连接,httpclient的处理方式是和http方式完全一样。 现在这里是讲的是需要客户端认证数字证书时的httpclient处理方式(因为需要客户端认证时,连接会被主动关闭)。 1。使用ie访问你要连结的url地址,这时你会看到弹出一个询问是否继续和服务器建立连接的对话框(安全警报)。选择“查看证书”->“详细信息”->“复制文件到”导出数字证书(例: server.cer或server.crt)。 2。使用导出的数字证书来创建你的keystore keytool -import -alias "my server cert" -file server.cer -keystore my.truststore keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore 3。在引入AuthSSLProtocolSocketFactory.java,AuthSSLX509TrustManager.java和AuthSSLInitializationError后在你的代码里按下面的例子里来进行ssl连接 Protocol authhttps = new Protocol("https",       new AuthSSLProtocolSocketFactory(         new URL("file:my.keystore"), "mypassword",         new URL("file:my.truststore"), "mypassword"), 8443); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost("sh.12530", 8443, authhttps); /*只能使用相对路径*/ GetMethod httpget = new GetMethod("/"); client.executeMethod(httpget); 附录: AuthSSLInitializationError.java public class AuthSSLInitializationError extends Error {     /**
         * 构招一个AuthSSLInitializationError实例
         */
        public AuthSSLInitializationError() {
            super();
        }     /**
         * 用指定信息构造一个AuthSSLInitializationError实例
         * @param message
         */
        public AuthSSLInitializationError(String message) {
            super(message);
        }
    }