Home > Back-end >  Send HTTPS requests to return to the Unrecognized SSL message
Send HTTPS requests to return to the Unrecognized SSL message

Time:11-25

Watch a lot of posts would say the url HTTPS instead of HTTP,

But the other said services is HTTPS,

What's the solution?

CodePudding user response:

1. Let the other side to provide certificate;
2. Send configuration HTTPS requests to ignore certificate;

CodePudding user response:

May provide service with not HTTPS port
https://blog.csdn.net/dtlscsl/article/details/50462721

CodePudding user response:

You use what version of the JDK and httpclient module?

CodePudding user response:

 public class SkipSslVerificationHttpRequestFactory extends SimpleClientHttpRequestFactory {

@ Override
Protected void prepareConnection (HttpURLConnection connection, String httpMethod)
Throws IOException {
If (connection instanceof HttpsURLConnection) {
PrepareHttpsConnection ((HttpsURLConnection) connection);
}
Super. PrepareConnection (connection, httpMethod);
}

Private void prepareHttpsConnection (HttpsURLConnection connection) {
Connection. SetHostnameVerifier (new SkipHostnameVerifier ());
Try {
Connection. SetSSLSocketFactory (createSslSocketFactory ());
{} the catch (Exception ex)
//Ignore
}
}

Private SSLSocketFactory createSslSocketFactory () throws the Exception {
SSLContext context=SSLContext. GetInstance (" TLS ");
The context. The init (null, new TrustManager [] {new SkipX509TrustManager ()},
New SecureRandom ());
Return the context. GetSocketFactory ();
}

Private class SkipHostnameVerifier implements HostnameVerifier {

@ Override
Public Boolean verify (String s, SSLSession SSLSession) {
return true;
}

}

Private static class SkipX509TrustManager implements X509TrustManager {

@ Override
Public X509Certificate [] getAcceptedIssuers () {
Return new X509Certificate [0];
}

@ Override
Public void checkClientTrusted (X509Certificate [] chain, String authType) {
}

@ Override
Public void checkServerTrusted (X509Certificate [] chain, String authType) {
}

}
}


@ Bean
Public RestTemplate RestTemplate () {
SkipSslVerificationHttpRequestFactory factory=new SkipSslVerificationHttpRequestFactory ();
Factory. SetReadTimeout (10000);
Factory. SetConnectTimeout (15000);
Return new RestTemplate (factory);
}


 
  • Related