{"id":35790,"date":"2024-11-26T13:48:57","date_gmt":"2024-11-26T05:48:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35790\/"},"modified":"2024-11-26T13:48:57","modified_gmt":"2024-11-26T05:48:57","slug":"post-%e8%af%b7%e6%b1%82%e5%8f%91%e9%80%81%e6%95%b0%e6%8d%ae%e5%90%8e%ef%bc%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%bf%90%e8%a1%8c%e4%b8%80%e6%ae%b5%e6%97%b6%e9%97%b4%e5%87%ba%e7%8e%b0%e7%a9%ba%e6%8c%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35790\/","title":{"rendered":"POST \u8bf7\u6c42\u53d1\u9001\u6570\u636e\u540e\uff0c\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173073024381886.jpg\" class=\"aligncenter\" title=\"POST \u8bf7\u6c42\u53d1\u9001\u6570\u636e\u540e\uff0c\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f\u63d2\u56fe\" alt=\"POST \u8bf7\u6c42\u53d1\u9001\u6570\u636e\u540e\uff0c\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>post\u5411https\u63a5\u53e3\u53d1\u9001\u6570\u636e \u90e8\u7f72\u5230\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u4f1a\u62a5\u7a7a\u6307\u9488\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f<\/strong><\/p>\n<p>\u5df2\u77e5\uff1a\u90e8\u7f72\u5230\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u4f1a\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\u3002<\/p>\n<p>\u4ee3\u7801\u4e2d\u7591\u4f3c\u51fa\u73b0\u5f02\u5e38\u7684\u90e8\u5206\uff1a<\/p>\n<pre>outputstreamwriter out = new outputstreamwriter(conn.getoutputstream(), \"utf-8\");\nout.write(gson.tojson(orderinfo));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u91c7\u7528\u5c01\u88c5\u7684\u65b9\u6cd5\u5904\u7406post\u8bf7\u6c42\uff0c\u907f\u514d\u56e0\u5f02\u5e38\u5bfc\u81f4\u7a7a\u6307\u9488\u95ee\u9898\u3002<\/p>\n<p><strong>\u4fee\u6539\u540e\u7684\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>orderinfo orderinfo = new orderinfo();\n\/\/ \u586b\u5145 orderinfo \u6570\u636e\n\nstring posturl = \"api\u5730\u5740\";\nstring postdata = converttojsonstring(orderinfo);\nstring result = httprequestutil.sendpost(posturl, postdata);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>httprequestutil.java \u4e2d sendpost \u65b9\u6cd5\uff1a<\/strong><\/p>\n<pre>public static String sendPost(String url, String postData) {\n    String data = null;\n    try {\n        URL dataUrl = new URL(url);\n        HttpURLConnection con = (HttpURLConnection) dataUrl.openConnection();\n        con.setRequestMethod(\"POST\");\n        con.setRequestProperty(\"Content-type\", \"application\/json\");\n        con.setDoOutput(true);\n        con.setDoInput(true);\n        con.setUseCaches(false);\n\n        OutputStream os = con.getOutputStream();\n        DataOutputStream dos = new DataOutputStream(os);\n        if (postData != null) {\n            dos.write(postData.getBytes(\"UTF-8\"));\n        }\n        dos.flush();\n        dos.close();\n\n        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), \"UTF-8\"));\n        StringBuffer buffer = new StringBuffer();\n        String line;\n        while ((line = in.readLine()) != null) {\n            buffer.append(line);\n        }\n        data = buffer.toString();\n        con.disconnect();\n    } catch (Exception ex) {\n        \/\/ \u5904\u7406\u5f02\u5e38\n    }\n    return data;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPOST \u8bf7\u6c42\u53d1\u9001\u6570\u636e\u540e\uff0c\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>post\u5411https\u63a5\u53e3\u53d1\u9001\u6570\u636e \u90e8\u7f72\u5230\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u4f1a\u62a5\u7a7a\u6307\u9488\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\uff1f \u5df2\u77e5\uff1a\u90e8\u7f72\u5230\u670d\u52a1\u5668\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u4f1a\u51fa\u73b0\u7a7a\u6307\u9488\u5f02\u5e38\u3002 \u4ee3\u7801\u4e2d\u7591\u4f3c\u51fa\u73b0\u5f02\u5e38\u7684\u90e8\u5206\uff1a outputstreamwriter out = new outputstreamwriter(conn.getoutputstream(), &#8220;utf-8&#8221;); out.write(gson.tojson(orderinfo)); \u767b\u5f55\u540e\u590d\u5236 \u89e3\u51b3\u65b9\u6848\uff1a \u91c7\u7528\u5c01\u88c5\u7684\u65b9\u6cd5\u5904\u7406post\u8bf7\u6c42\uff0c\u907f\u514d\u56e0\u5f02\u5e38\u5bfc\u81f4\u7a7a\u6307\u9488\u95ee\u9898\u3002 \u4fee\u6539\u540e\u7684\u4ee3\u7801\uff1a orderinfo orderinfo = new orderinfo(); \/\/ \u586b\u5145 orderinfo \u6570\u636e string posturl = &#8220;api\u5730\u5740&#8221;; string postdata = converttojsonstring(orderinfo); string result = httprequestutil.sendpost(posturl, postdata); \u767b\u5f55\u540e\u590d\u5236 httprequestutil.java \u4e2d sendpost \u65b9\u6cd5\uff1a public static String sendPost(String url, String postData) { String data = null; try [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35790","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35790"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35790\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}