{"id":203328,"date":"2025-05-22T11:01:01","date_gmt":"2025-05-22T03:01:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203328\/"},"modified":"2025-05-22T11:01:01","modified_gmt":"2025-05-22T03:01:01","slug":"https-%e6%8e%a5%e5%8f%a3%e5%8f%91%e9%80%81%e6%95%b0%e6%8d%ae%e6%97%b6%e5%87%ba%e7%8e%b0%e7%a9%ba%e6%8c%87%e9%92%88%e5%bc%82%e5%b8%b8%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203328\/","title":{"rendered":"HTTPS \u63a5\u53e3\u53d1\u9001\u6570\u636e\u65f6\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>HTTPS \u63a5\u53e3\u53d1\u9001\u6570\u636e\u65f6\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aHTTPS \u63a5\u53e3\u53d1\u9001\u6570\u636e\u65f6\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241105\/17307713246729797ce1525.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>post \u5411 https \u63a5\u53e3\u53d1\u9001\u6570\u636e\uff0c\u90e8\u7f72\u5230\u670d\u52a1\u5668\u540e\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u62a5\u7a7a\u6307\u9488\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u95ee\u9898\u4e2d\u7ed9\u51fa\u7684\u4ee3\u7801\u7247\u6bb5\u4e2d\uff0c\u5f02\u5e38\u51fa\u73b0\u5728\u521b\u5efa outputstreamwriter \u5bf9\u8c61\u65f6\uff0c\u5373\uff1a<\/p>\n<pre>outputstreamwriter out = new outputstreamwriter(conn.getoutputstream(), \"utf-8\");<\/pre>\n<p>\u6b64\u884c\u4ee3\u7801\u4e2d\uff0cconn \u4e3a\u4e00\u4e2a httpsurlconnection \u5bf9\u8c61\uff0c\u8c03\u7528\u5176 getoutputstream() \u65b9\u6cd5\u65f6\u51fa\u73b0\u4e86\u7a7a\u6307\u9488\u5f02\u5e38\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>conn \u5bf9\u8c61\u672a\u6b63\u786e\u5efa\u7acb\u8fde\u63a5\u3002<\/li>\n<li>\u670d\u52a1\u5668\u7aef\u53d1\u751f\u5f02\u5e38\u5bfc\u81f4\u65e0\u6cd5\u83b7\u53d6\u8f93\u51fa\u6d41\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5efa\u8bae\u4f7f\u7528\u4e00\u4e2a\u5355\u72ec\u7684\u65b9\u6cd5\u4e13\u95e8\u7528\u4e8e\u53d1\u9001 post \u8bf7\u6c42\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5199\u6b7b url \u548c\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4fee\u6539\u540e\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>public static String sendPost(String url, String postData) {\n    HttpsURLConnection conn = null;\n    OutputStreamWriter out = null;\n    BufferedReader in = null;\n    String result = null;\n\n    try {\n        URL dataUrl = new URL(url);\n        conn = (HttpsURLConnection) dataUrl.openConnection();\n        conn.setRequestMethod(\"POST\");\n        conn.setRequestProperty(\"Content-Type\", \"application\/json\");\n        conn.setDoOutput(true);\n        conn.setDoInput(true);\n        conn.setUseCaches(false);\n\n        out = new OutputStreamWriter(conn.getOutputStream(), \"UTF-8\");\n        out.write(postData);\n        out.flush();\n\n        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));\n        StringBuffer buffer = new StringBuffer();\n        String line;\n        while ((line = in.readLine()) != null) {\n            buffer.append(line);\n        }\n        result = buffer.toString();\n    } catch (Exception ex) {\n        ex.printStackTrace();\n    } finally {\n        try {\n            if (out != null) {\n                out.close();\n            }\n            if (in != null) {\n                in.close();\n            }\n            if (conn != null) {\n                conn.disconnect();\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n\n    return result;\n}\n\n\/\/ \u8c03\u7528\u65b9\u6cd5\nOrderInfo orderInfo = new OrderInfo();\n\/\/ ... \u8bbe\u7f6e\u5404\u79cd\u6570\u636e\nString url = \"https:\/\/example.com\/api\/endpoint\";\nString postData = GsonUtils.convertToJson(orderInfo);\nString result = sendPost(url, postData);<\/pre>\n<p>\u5176\u4e2d\uff0cgsonutils \u662f\u4e00\u4e2a\u7528\u4e8e json \u8f6c\u6362\u7684\u5de5\u5177\u7c7b\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u884c\u5b9e\u73b0\u6216\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002<\/p>\n<p>\u901a\u8fc7\u5c01\u88c5\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e post \u8bf7\u6c42\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u8fde\u63a5\u5efa\u7acb\u7684\u8fc7\u7a0b\uff0c\u5e76\u907f\u514d\u7a7a\u6307\u9488\u5f02\u5e38\u7684\u53d1\u751f\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aHTTPS \u63a5\u53e3\u53d1\u9001\u6570\u636e\u65f6\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTTPS \u63a5\u53e3\u53d1\u9001\u6570\u636e\u65f6\u51fa\u73b0\u7a7a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203328","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203328"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203328\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}