Home > Back-end >  HttpClient access HTTPS
HttpClient access HTTPS

Time:09-16

Why can't help to see me this configuration, visit HTTPS interface

The static {
ConnectionSocketFactory plainsf=PlainConnectionSocketFactory. GetSocketFactory ();
SSLContext sc;
Try {
Sc=SSLContext. GetInstance (" TLS ");
TrustManager trustAllCerts=new TrustManager [] [] {new X509TrustManager () {
@ Override
Public void checkClientTrusted (X509Certificate [] x509Certificates, String s) throws CertificateException {
}
@ Override
Public void checkServerTrusted (X509Certificate [] x509Certificates, String s) throws CertificateException {
}
@ Override
Public X509Certificate [] getAcceptedIssuers () {
return null;
}
}};
Sc. Init (null, trustAllCerts, null);
} the catch (Exception e) {
The LOG. The error (" some thing happen ", e);
Throw new ServiceException (e);
}
ConnectionSocketFactory SSLSF=new SSLConnectionSocketFactory (sc, (s, sslSession) - & gt; True);
ConnectionKeepAliveStrategy ConnectionKeepAliveStrategy=(httpResponse httpContext) - & gt; {
The return of 20 l * 1000;
};
Registry Registry=RegistryBuilder. & lt; ConnectionSocketFactory> Create ()
Register (" HTTP ", plainsf). Register (" FTP ", plainsf). Register (" HTTPS, "SSLSF). The build ();
PoolingHttpClientConnectionManager connManager=new PoolingHttpClientConnectionManager (registry);
ConnManager. SetMaxTotal (400);
ConnManager. SetDefaultMaxPerRoute (200);
RequestConfig RequestConfig=RequestConfig. Custom (.) setConnectTimeout (HTTP_CONNECT_TIME_OUT)
SetConnectionRequestTimeout (3000). SetSocketTimeout (HTTP_TIME_OUT). The build ();
The client=HttpClients. Custom (.) setConnectionManager (connManager)
SetRetryHandler (new DefaultHttpRequestRetryHandler ()). SetDefaultRequestConfig (requestConfig)
SetKeepAliveStrategy (connectionKeepAliveStrategy). The build ();
}

CodePudding user response:

Baidu is so worthy, to I this not line, finally returned to the client object should be able to access the HTTPS interface on principle

CodePudding user response:

What is the error information?

CodePudding user response:

refer to the second floor dkwuxiang response:
error message?


15:37:14. 226. [the main] the DEBUG org. Apache. HTTP. Impl. Execchain. MainClientExec - Opening connection {s} - & gt; https://www.baidu.com:443
15:37:14. 241. [the main] the DEBUG org. Apache. HTTP. Impl. Conn. DefaultHttpClientConnectionOperator - Connecting to www.baidu.com/180.101.49.11:443
15:37:14. 241. [the main] the DEBUG org. Apache. HTTP. Conn. SSL. SSLConnectionSocketFactory - Connecting socket to www.baidu.com/180.101.49.11:443 with a timeout 15000
15:37:29. 244. [the main] the DEBUG org. Apache. HTTP. Impl. Conn. DefaultHttpClientConnectionOperator - Connect to www.baidu.com/180.101.49.11:443 timed out. The Connection will be retried using another IP address
15:37:29. 244. [the main] the DEBUG org. Apache. HTTP. Impl. Conn. DefaultHttpClientConnectionOperator - Connecting to www.baidu.com/180.101.49.12:443
15:37:29. 244. [the main] the DEBUG org. Apache. HTTP. Conn. SSL. SSLConnectionSocketFactory - Connecting socket to www.baidu.com/180.101.49.12:443 with a timeout 15000
15:37:44. 247. [the main] the DEBUG org. Apache. HTTP. Impl. Conn. DefaultManagedHttpClientConnection - HTTP - outgoing - 0: Shutdown connection
15:37:44. 248. [the main] the DEBUG org. Apache. HTTP. Impl. Execchain. MainClientExec - Connection discarded
15:37:44. 249. [the main] the DEBUG org. Apache. HTTP. Impl. Conn. PoolingHttpClientConnectionManager - Connection released: [id: 0] [the route: {s} - & gt;https://www.baidu.com: 443] [total kept alive: 0; the route allocated: 0 of 200; the total allocated: 0 of 400]
15:37:44. [the main] ERROR 249 com.suning.itp.thor.com mon. Utils. RestClient - send a number of https://www.baidu.com: 0 request returns information: {}, {}
15:37:44. [the main] ERROR 250 com.suning.itp.thor.com mon. Utils. RestClient - the abnormal, the HTTP request number: 0, information: org. Apache. HTTP. Conn. ConnectTimeoutException, Connect to www.baidu.com:443 (www.baidu.com/180.101.49.11, www.baidu.com/180.101.49.12) failed: Connect timed out
15:37:46. [the main] ERROR 258 com.suning.itp.thor.com mon. Utils. RestClient - HTTP request failure
Org. Apache. HTTP. Conn. ConnectTimeoutException: Connect to www.baidu.com:443 (www.baidu.com/180.101.49.11, www.baidu.com/180.101.49.12) failed: Connect timed out
The at org. Apache. HTTP. Impl. Conn. DefaultHttpClientConnectionOperator. Connect (DefaultHttpClientConnectionOperator. Java: 151)
The at org. Apache. HTTP. Impl. Conn. PoolingHttpClientConnectionManager. Connect (PoolingHttpClientConnectionManager. Java: 373)
The at org. Apache. HTTP. Impl. Execchain. MainClientExec. EstablishRoute (MainClientExec. Java: 394)
The at org. Apache. HTTP. Impl. Execchain. MainClientExec. Execute (MainClientExec. Java: 237)
The at org. Apache. HTTP. Impl. Execchain. ProtocolExec. Execute (ProtocolExec. Java: 185)
The at org. Apache. HTTP. Impl. Execchain. RetryExec. Execute (RetryExec. Java: 89)
The at org. Apache. HTTP. Impl. Execchain. RedirectExec. Execute (RedirectExec. Java: 110)
The at org. Apache. HTTP. Impl. Client. InternalHttpClient. The doExecute (InternalHttpClient. Java: 185)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related