Mercurial > hg > Blog
comparison content/Java/commons-httpclient-vs-self-signed-certs.md @ 98:1d9382b0329b
Specify the syntax on markdown blocks to avoid broken output that has class=err
| author | Dirk Olmes <dirk@xanthippe.ping.de> |
|---|---|
| date | Thu, 19 Dec 2019 10:04:33 +0100 |
| parents | ba3f2e5c6950 |
| children |
comparison
equal
deleted
inserted
replaced
| 97:e99db3bc53c1 | 98:1d9382b0329b |
|---|---|
| 7 | 7 |
| 8 So how does all the talk about socket factories and SSLContext and friends go together with your [HttpClient](http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/HttpClient.html)? | 8 So how does all the talk about socket factories and SSLContext and friends go together with your [HttpClient](http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/HttpClient.html)? |
| 9 | 9 |
| 10 Let's assume you already have a HttpClient instance at hand: | 10 Let's assume you already have a HttpClient instance at hand: |
| 11 | 11 |
| 12 :::java | |
| 12 HttpClient client = new DefaultHttpClient(); | 13 HttpClient client = new DefaultHttpClient(); |
| 13 | 14 |
| 14 Now let's configure all the socket factories and stuff that's required to make HTTPS traffic with self signed certificates work: | 15 Now let's configure all the socket factories and stuff that's required to make HTTPS traffic with self signed certificates work: |
| 15 | 16 |
| 17 :::java | |
| 16 TrustStrategy trustStrategy = new TrustSelfSignedStrategy(); | 18 TrustStrategy trustStrategy = new TrustSelfSignedStrategy(); |
| 17 X509HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; | 19 X509HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; |
| 18 SchemeSocketFactory socketFactory = new SSLSocketFactory(trustStrategy, hostnameVerifier); | 20 SchemeSocketFactory socketFactory = new SSLSocketFactory(trustStrategy, hostnameVerifier); |
| 19 | 21 |
| 20 And now let's put it all together: | 22 And now let's put it all together: |
| 21 | 23 |
| 24 :::java | |
| 22 Scheme https = new Scheme("https", 443, socketFactory); | 25 Scheme https = new Scheme("https", 443, socketFactory); |
| 23 SchemeRegistry registry = client.getConnectionManager().getSchemeRegistry(); | 26 SchemeRegistry registry = client.getConnectionManager().getSchemeRegistry(); |
| 24 registry.register(https); | 27 registry.register(https); |
