2016-01-26 177 views

回答

4

您應該能夠使用TSLSocketConnectionFactory與HttpClient的類似以下內容:

SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(new TLSSocketConnectionFactory(), new String[]{"TLSv1.2"}, null, new DefaultHostnameVerifier()); 
HttpClient client = HttpClientBuilder.create() 
      .setSSLSocketFactory(sf) 
      .build(); 

您可能需要改變一些在TSLSocketConnectionFactory的方法的SSLSession實現的。

在我而言,當我試圖與HttpClient的使用它,我不得不改變如下:

在的SSLSocket()實現:

@Override 
public String[] getEnabledCipherSuites() {   
    // return null; 
    return new String[]{""}; 
} 

@Override 
public String[] getEnabledProtocols() { 
    // return null; 
    return new String[]{""}; 
} 

在的SSLSession()實現:

@Override 
public String getProtocol() { 
// throw new UnsupportedOperationException(); 
    return null; 
} 
@Override 
public String getProtocol() { 
// throw new UnsupportedOperationException(); 
    return ""; 
} 
@Override 
public String getCipherSuite() { 
// throw new UnsupportedOperationException(); 
    return "": 
}