收到的致命警报:使用HttpClient API的JDK 1.7的handshake_failure

时间:2019-04-24 16:18:54

标签: java wildfly java-7

我正在尝试使用“ HttpClient API”方法与另一个https URL通信。但我收到以下异常:

SSLHandshakeException:收到致命警报:handshake_failure

JDK 1.7

服务器:Wildfly 9

我也将证书导入了密钥存储区

Java code

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.MultipartPostMethod;
import org.apache.commons.httpclient.protocol.Protocol;

class SSLTest {
    public static void main(String args[]) {    
        String responseString = ""; 
        String sslStr = "https";
        String urlString ="https://<urlString>/Registration?Param1=test";
        HttpClient client = new HttpClient();
        if(sslStr.equals("https")){
           try{
            Protocol httpsProtocol = new Protocol( "https", new EasySSLProtocolSocketFactory(), serverPort);
            Protocol.registerProtocol("https", httpsProtocol);
            client.getHostConfiguration().setHost(serverip, serverPort,httpsProtocol);
           }catch(Exception e2){
               System.out.println("Fail to create certificate :"+e2.getMessage());
           }
        }
        MultipartPostMethod mPost = new MultipartPostMethod(urlString);
        client.setConnectionTimeout(1000*3*60);

        try{
        int statusCode = client.executeMethod(mPost);
        }catch(Exception e2){
            System.out.println("Exception: "+e2.getMessage());
        }
        responseString = mPost.getResponseBodyAsString();
        mPost.releaseConnection();

        System.out.println("responseString = " + responseString);
    }
}   

-------
Output
-------

Exception: Received fatal alert: handshake_failure

responseString = NULL

预期输出:它应该到达指定的URL服务器。但是在这里,无法与服务器通信。

谢谢。

0 个答案:

没有答案