{"id":1008,"date":"2007-10-02T09:19:47","date_gmt":"2007-10-02T17:19:47","guid":{"rendered":"http:\/\/cephas.net\/blog\/2007\/10\/02\/using-a-custom-socket-factory-with-httpclient\/"},"modified":"2007-10-02T09:19:47","modified_gmt":"2007-10-02T17:19:47","slug":"using-a-custom-socket-factory-with-httpclient","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2007\/10\/02\/using-a-custom-socket-factory-with-httpclient\/","title":{"rendered":"Using a custom socket factory with HttpClient"},"content":{"rendered":"<p>The documentation on <a href=\"http:\/\/jakarta.apache.org\/httpcomponents\/httpclient-3.x\/sslguide.html\">how to use a custom socket factory in HttpClient<\/a> is actually pretty good, but there&#8217;s one thing they don&#8217;t make very clear. If you want to specify a per-host socket factory like this:<\/p>\n<pre>\r\nProtocol p = new Protocol(\"https\", new MySSLSocketFactory(), 443);\r\nHttpClient httpclient = new HttpClient();\r\nhttpclient.getHostConfiguration().setHost(\"example.com\", 443, p);\r\nGetMethod httpget = new GetMethod(\"\/mypath\");\r\n<\/pre>\n<p><strong>you must<\/strong> specify a path and not the full URL in the GetMethod constructor. If you don&#8217;t, in other words, if you use a constructor like this:<\/p>\n<pre>\r\nGetMethod httpget = new GetMethod(\"https:\/\/example.com\/mypath\");\r\n<\/pre>\n<p>the custom socket factory you specified in the host configuration will not be used. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The documentation on how to use a custom socket factory in HttpClient is actually pretty good, but there&#8217;s one thing they don&#8217;t make very clear. If you want to specify a per-host socket factory like this: Protocol p = new Protocol(&#8220;https&#8221;, new MySSLSocketFactory(), 443); HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setHost(&#8220;example.com&#8221;, 443, p); GetMethod httpget = &hellip; <a href=\"https:\/\/cephas.net\/blog\/2007\/10\/02\/using-a-custom-socket-factory-with-httpclient\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using a custom socket factory with HttpClient<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4,12],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/1008"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=1008"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/1008\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=1008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=1008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=1008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}