{"id":1659,"date":"2014-10-20T23:31:11","date_gmt":"2014-10-20T15:31:11","guid":{"rendered":"http:\/\/learn-house.idv.tw\/?p=1659"},"modified":"2014-10-20T23:33:54","modified_gmt":"2014-10-20T15:33:54","slug":"androidhttpclient%e5%af%a6%e4%bd%9chttps%e8%88%87%e5%bc%b7%e5%88%b6%e5%85%81%e8%a8%b1%e8%87%aa%e7%b0%bd%e6%86%91%e8%ad%89self-signed-certificate","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=1659","title":{"rendered":"[Android]HttpClient\u5be6\u4f5cHTTPs\u8207\u5f37\u5236\u5141\u8a31\u81ea\u7c3d\u6191\u8b49(Self-Signed Certificate)"},"content":{"rendered":"<p>HttpClient\u662f\u65e9\u671fAndroid\u63d0\u4f9b\u53ef\u4ee5\u7528\u4f86\u8207WebServer\u6e9d\u901a\u7684API<\/p>\n<p>Android2.3\u4e4b\u5f8c\u5c31\u5efa\u8b70\u4f7f\u7528\u65b0\u7684HttpURLConnection\uff0c\u9019\u88e1\u6211\u5c31\u4e0d\u5728\u8d05\u8ff0<\/p>\n<p>\u6709\u95dcHttpClient\u8207\u65b0\u7248\u7684HttpURLConnection\u5dee\u5225<\/p>\n<p>\u8acb\u76f4\u63a5\u770b\u4e0a\u4e00\u7bc7<a title=\"Permanent Link to [Android]HttpsURLConnection\u5be6\u4f5cHTTPs\u8207\u5f37\u5236\u5141\u8a31\u81ea\u7c3d\u6191\u8b49(Self-Signed Certificate)\" rel=\"bookmark\" href=\"http:\/\/learn-house.idv.tw\/?p=1639\" target=\"_blank\">HttpsURLConnection\u5be6\u4f5cHTTPs\u8207\u5f37\u5236\u5141\u8a31\u81ea\u7c3d\u6191\u8b49(Self-Signed Certificate)<\/a><\/p>\n<p>\u4e0d\u591a\u8aaa\uff0c\u5c31\u76f4\u63a5\u770bCode\u5427\uff1a<!--more--><\/p>\n<p>[java]<\/p>\n<p>\t\t\t\tSchemeRegistry schemeRegistry = new SchemeRegistry();<br \/>\n\t\t\t\t\/\/ http scheme<br \/>\n\t\t\t\tschemeRegistry.register(new Scheme(&quot;http&quot;, PlainSocketFactory.getSocketFactory(), 80));<br \/>\n\t\t\t\t\/\/ https scheme<br \/>\n\t\t\t\tschemeRegistry.register(new Scheme(&quot;https&quot;, new EasySSLSocketFactory(), 443));<\/p>\n<p>\t\t\t\tHttpParams params = new BasicHttpParams();<br \/>\n\t\t\t\tparams.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);<br \/>\n\t\t\t\tparams.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));<br \/>\n\t\t\t\tparams.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);<br \/>\n\t\t\t\tHttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);<\/p>\n<p>\t\t\t\tClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);<br \/>\n\t\t\t\tHttpClient client = new DefaultHttpClient(cm, params);<\/p>\n<p>\t\t\t\tfinal HttpPost post = new HttpPost(&quot;https:\/\/127.0.0.1\/login.php&quot;);<br \/>\n\t\t\t\tpost.setHeader(&quot;Connection&quot;, &quot;Keep-Alive&quot;);<br \/>\n\t\t\t\tpost.setHeader(&quot;Content-Type&quot;, &quot;multipart\/form-data&quot;);<br \/>\n\t\t\t\t\/*\u4ee5\u4e0b\u7701\u7565*\/<\/p>\n<p>[\/java]<\/p>\n<p>\u5176\u4e2d\u7f3a\u7684<a href=\"https:\/\/code.google.com\/p\/exchangeit\/source\/browse\/trunk\/src\/com\/byarger\/exchangeit\/EasySSLSocketFactory.java?spec=svn23&amp;r=23\" target=\"_blank\">EasySSLSocketFactory<\/a>\u8207<a href=\"https:\/\/code.google.com\/p\/exchangeit\/source\/browse\/trunk\/src\/com\/byarger\/exchangeit\/EasyX509TrustManager.java?spec=svn23&amp;r=23\" target=\"_blank\">EasyX509TrustManager<\/a>\u53ef\u4ee5\u76f4\u63a5\u9ede\u9078\u9023\u7d50\u5f8c\u8907\u88fd<\/p>\n<p>\u56e0\u70ba\u9019\u5169\u96bb\u7a0b\u5f0f\u6709\u4f7f\u7528Apache\u7684License\uff0c\u56e0\u6b64\u6211\u5c31\u4e0d\u8cbc\u4e0a\u4f86\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HttpClient\u662f\u65e9\u671fAndroid\u63d0\u4f9b\u53ef\u4ee5\u7528\u4f86\u8207WebServer\u6e9d\u901a\u7684API Android2.3\u4e4b\u5f8c<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/learn-house.idv.tw\/?p=1659\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1659","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1659"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1659\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}