{"id":23129,"date":"2024-11-21T09:37:15","date_gmt":"2024-11-21T01:37:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23129\/"},"modified":"2024-11-21T09:37:15","modified_gmt":"2024-11-21T01:37:15","slug":"thinkphp%e8%8e%b7%e5%8f%96%e4%b8%8d%e5%88%b0post%e6%95%b0%e6%8d%ae%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23129\/","title":{"rendered":"thinkphp\u83b7\u53d6\u4e0d\u5230post\u6570\u636e\u5982\u4f55\u89e3\u51b3"},"content":{"rendered":"<\/p>\n<p><strong>\u4e00\u3001\u95ee\u9898\u73b0\u8c61<\/strong><\/p>\n<p>\u63d0\u4ea4\u8868\u5355\u540e\uff0c\u901a\u8fc7 request-&gt;param() \u6216 $this-&gt;request-&gt;param() \u83b7\u53d6\u4e0d\u5230 post \u6570\u636e\uff0c\u5f97\u5230\u7684\u662f\u7a7a\u6570\u7ec4\u3002<\/p>\n<p><strong>\u4e8c\u3001\u95ee\u9898\u539f\u56e0<\/strong><\/p>\n<ol>\n<li>\n<p>\u8868\u5355\u4e2d\u6ca1\u6709\u8bbe\u7f6e enctype \u5c5e\u6027<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<\/li>\n<\/ol>\n<p>\u5728\u8868\u5355\u63d0\u4ea4\u65f6\uff0c\u5982\u679c enctype \u5c5e\u6027\u6ca1\u6709\u8bbe\u7f6e\uff0c\u90a3\u4e48\u9ed8\u8ba4\u7684\u6570\u636e\u4f20\u8f93\u65b9\u5f0f\u662f application\/x-www-form-urlencoded\u3002\u73b0\u5728\uff0c\u6570\u636e\u5c06\u88ab\u653e\u7f6e\u5728 HTTP \u8bf7\u6c42\u5934\u90e8\u800c\u975e\u8bf7\u6c42\u4f53\u4e2d\u3002\u6240\u4ee5\uff0c\u5728\u83b7\u53d6 post \u6570\u636e\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 $this-&gt;request-&gt;post() \u6216\u8005 request()-&gt;post()\u3002<\/p>\n<ol>\n<li>\n<p>\u63a5\u53e3\u8c03\u7528\u65f6\u6ca1\u6709\u8bbe\u7f6e\u8bf7\u6c42\u5934<\/p>\n<\/li>\n<\/ol>\n<p>\u5728\u63a5\u53e3\u8c03\u7528\u65f6\uff0c\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u76f8\u5e94\u7684\u8bf7\u6c42\u5934\uff0c\u6bd4\u5982 Content-Type\uff1aapplication\/json\uff0c\u5426\u5219\u670d\u52a1\u5668\u65e0\u6cd5\u89e3\u6790\u6570\u636e\u3002\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e Content-Type\uff0c\u5219\u670d\u52a1\u5668\u9ed8\u8ba4\u4e3a application\/x-www-form-urlencoded\uff0c\u800c\u6b64\u65f6 post \u7684\u6570\u636e\u4f1a\u653e\u5728 http \u8bf7\u6c42\u5934\u4e2d\uff0c\u800c\u4e0d\u662f\u8bf7\u6c42\u4f53\u4e2d\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u786e\u83b7\u53d6 post \u6570\u636e\u3002<\/p>\n<p><strong>\u4e09\u3001\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<ol>\n<li>\n<p>\u8bbe\u7f6e enctype \u5c5e\u6027<\/p>\n<\/li>\n<\/ol>\n<p>\u5728\u8868\u5355\u4e2d\u6dfb\u52a0 enctype=&#8221;multipart\/form-data&#8221;\uff0c\u8fd9\u6837\u5c31\u80fd\u591f\u6b63\u786e\u83b7\u53d6 post \u6570\u636e\u4e86\u3002<\/p>\n<ol>\n<li>\n<p>\u8bbe\u7f6e\u8bf7\u6c42\u5934<\/p>\n<\/li>\n<\/ol>\n<p>\u5728\u63a5\u53e3\u8c03\u7528\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 curl \u8bbe\u7f6e\u8bf7\u6c42\u5934\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>$data&nbsp;=&nbsp;array(\n&nbsp;&nbsp;&nbsp;&nbsp;'username'&nbsp;=&amp;gt;&nbsp;'admin',\n&nbsp;&nbsp;&nbsp;&nbsp;'password'&nbsp;=&amp;gt;&nbsp;'123456'\n);\n\n$url&nbsp;=&nbsp;'http:\/\/www.example.com\/login';\n$ch&nbsp;=&nbsp;curl_init();\n\n$header&nbsp;=&nbsp;array(\n&nbsp;&nbsp;&nbsp;&nbsp;'Content-Type:&nbsp;application\/json',\n&nbsp;&nbsp;&nbsp;&nbsp;'Content-Length:&nbsp;'.strlen(json_encode($data))\n);\n\ncurl_setopt($ch,&nbsp;CURLOPT_URL,&nbsp;$url);\ncurl_setopt($ch,&nbsp;CURLOPT_POST,&nbsp;1);\ncurl_setopt($ch,&nbsp;CURLOPT_POSTFIELDS,&nbsp;json_encode($data));\ncurl_setopt($ch,&nbsp;CURLOPT_HTTPHEADER,&nbsp;$header);\ncurl_setopt($ch,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1);\n\n$res&nbsp;=&nbsp;curl_exec($ch);\ncurl_close($ch);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u83b7\u53d6\u4e0d\u5230post\u6570\u636e\u5982\u4f55\u89e3\u51b3\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>\u4e00\u3001\u95ee\u9898\u73b0\u8c61 \u63d0\u4ea4\u8868\u5355\u540e\uff0c\u901a\u8fc7 request-&gt;param() \u6216 $this-&gt;request-&gt;param() \u83b7\u53d6\u4e0d\u5230 post \u6570\u636e\uff0c\u5f97\u5230\u7684\u662f\u7a7a\u6570\u7ec4\u3002 \u4e8c\u3001\u95ee\u9898\u539f\u56e0 \u8868\u5355\u4e2d\u6ca1\u6709\u8bbe\u7f6e enctype \u5c5e\u6027 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728\u8868\u5355\u63d0\u4ea4\u65f6\uff0c\u5982\u679c enctype \u5c5e\u6027\u6ca1\u6709\u8bbe\u7f6e\uff0c\u90a3\u4e48\u9ed8\u8ba4\u7684\u6570\u636e\u4f20\u8f93\u65b9\u5f0f\u662f application\/x-www-form-urlencoded\u3002\u73b0\u5728\uff0c\u6570\u636e\u5c06\u88ab\u653e\u7f6e\u5728 HTTP \u8bf7\u6c42\u5934\u90e8\u800c\u975e\u8bf7\u6c42\u4f53\u4e2d\u3002\u6240\u4ee5\uff0c\u5728\u83b7\u53d6 post \u6570\u636e\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 $this-&gt;request-&gt;post() \u6216\u8005 request()-&gt;post()\u3002 \u63a5\u53e3\u8c03\u7528\u65f6\u6ca1\u6709\u8bbe\u7f6e\u8bf7\u6c42\u5934 \u5728\u63a5\u53e3\u8c03\u7528\u65f6\uff0c\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u76f8\u5e94\u7684\u8bf7\u6c42\u5934\uff0c\u6bd4\u5982 Content-Type\uff1aapplication\/json\uff0c\u5426\u5219\u670d\u52a1\u5668\u65e0\u6cd5\u89e3\u6790\u6570\u636e\u3002\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e Content-Type\uff0c\u5219\u670d\u52a1\u5668\u9ed8\u8ba4\u4e3a application\/x-www-form-urlencoded\uff0c\u800c\u6b64\u65f6 post \u7684\u6570\u636e\u4f1a\u653e\u5728 http \u8bf7\u6c42\u5934\u4e2d\uff0c\u800c\u4e0d\u662f\u8bf7\u6c42\u4f53\u4e2d\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u786e\u83b7\u53d6 post \u6570\u636e\u3002 \u4e09\u3001\u89e3\u51b3\u65b9\u6cd5 \u8bbe\u7f6e enctype \u5c5e\u6027 \u5728\u8868\u5355\u4e2d\u6dfb\u52a0 enctype=&#8221;multipart\/form-data&#8221;\uff0c\u8fd9\u6837\u5c31\u80fd\u591f\u6b63\u786e\u83b7\u53d6 post \u6570\u636e\u4e86\u3002 \u8bbe\u7f6e\u8bf7\u6c42\u5934 \u5728\u63a5\u53e3\u8c03\u7528\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 curl \u8bbe\u7f6e\u8bf7\u6c42\u5934\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a $data&nbsp;=&nbsp;array( &nbsp;&nbsp;&nbsp;&nbsp;&#8216;username&#8217;&nbsp;=&amp;gt;&nbsp;&#8216;admin&#8217;, &nbsp;&nbsp;&nbsp;&nbsp;&#8216;password&#8217;&nbsp;=&amp;gt;&nbsp;&#8216;123456&#8217; ); $url&nbsp;=&nbsp;&#8216;http:\/\/www.example.com\/login&#8217;; $ch&nbsp;=&nbsp;curl_init(); $header&nbsp;=&nbsp;array( &nbsp;&nbsp;&nbsp;&nbsp;&#8216;Content-Type:&nbsp;application\/json&#8217;, [&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-23129","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23129","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=23129"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23129\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}