{"id":46952,"date":"2024-12-02T11:34:46","date_gmt":"2024-12-02T03:34:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46952\/"},"modified":"2024-12-02T11:34:46","modified_gmt":"2024-12-02T03:34:46","slug":"php%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e6%8c%87%e5%8d%97%ef%bc%9apost%e5%92%8cget%e8%af%b7%e6%b1%82%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46952\/","title":{"rendered":"php\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>POST\u548cGET\u662f PHP \u7f51\u7edc\u7f16\u7a0b\u4e2d\u5e38\u89c1\u7684\u8bf7\u6c42\u65b9\u6cd5\u3002POST\u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u654f\u611f\u6216\u5927\u91cf\u6570\u636e\uff0c\u800cGET\u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u8f83\u5c11\u7684\u4e0d\u654f\u611f\u6570\u636e\u3002POST\u8bf7\u6c42\u7684\u6570\u636e\u5b89\u5168\u6027\u8f83\u9ad8\uff0c\u4e0d\u4f1a\u663e\u793a\u5728\u6d4f\u89c8\u5668\u7684\u5730\u5740\u680f\u4e2d\uff0c\u800cGET\u8bf7\u6c42\u4f1a\u663e\u793a\u5728\u5730\u5740\u680f\u4e2d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729856977671b85d124ceb.jpg\" class=\"aligncenter\" title=\"php\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3\u63d2\u56fe\" alt=\"php\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST \u548c GET \u8bf7\u6c42\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>\u5728 PHP \u7f51\u7edc\u7f16\u7a0b\u4e2d\uff0cPOST \u548c GET \u662f\u4e24\u79cd\u5e38\u7528\u7684\u8bf7\u6c42\u65b9\u6cd5\uff0c\u7528\u4e8e\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\u3002\u867d\u7136\u5b83\u4eec\u5728\u8bed\u6cd5\u4e0a\u76f8\u4f3c\uff0c\u4f46\u5b83\u4eec\u5728\u6570\u636e\u5904\u7406\u65b9\u5f0f\u548c\u4f7f\u7528\u573a\u666f\u4e0a\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002<\/p>\n<p><strong>POST \u8bf7\u6c42<\/strong><\/p>\n<ul>\n<li><strong>\u5b9a\u4e49\uff1a<\/strong>POST \u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u654f\u611f\u6216\u5927\u91cf\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u4e0d\u5e94\u663e\u793a\u5728\u6d4f\u89c8\u5668\u7684\u5730\u5740\u680f\u4e2d\u3002<\/li>\n<li>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>&lt;?php\n$url = \"https:\/\/example.com\/post_data.php\";\n$data = array('username' =&gt; 'john', 'email' =&gt; 'john@example.com');\n\n\/\/ \u4f7f\u7528 cURL \u53d1\u9001 POST \u8bf7\u6c42\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL, $url);\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));\n$response = curl_exec($ch);\ncurl_close($ch);\n?&gt;<\/pre>\n<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong>\u4f7f\u7528 POST \u8bf7\u6c42\u63d0\u4ea4\u767b\u5f55\u8868\u5355\u3002<\/li>\n<\/ul>\n<p><strong>GET \u8bf7\u6c42<\/strong><\/p>\n<ul>\n<li><strong>\u5b9a\u4e49\uff1a<\/strong>GET \u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u8f83\u5c11\u3001\u4e0d\u654f\u611f\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u663e\u793a\u5728\u6d4f\u89c8\u5668\u7684\u5730\u5740\u680f\u4e2d\u3002<\/li>\n<li>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>&lt;?php\n$url = \"https:\/\/example.com\/get_data.php?username=john&amp;email=john@example.com\";\n\n\/\/ \u4f7f\u7528 cURL \u53d1\u9001 GET \u8bf7\u6c42\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL, $url);\n$response = curl_exec($ch);\ncurl_close($ch);\n?&gt;<\/pre>\n<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong>\u4f7f\u7528 GET \u8bf7\u6c42\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><strong>POST \u548c GET \u8bf7\u6c42\u4e4b\u95f4\u7684\u5dee\u5f02<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u5f81<\/th>\n<th>POST<\/th>\n<th>GET<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u6570\u636e\u5927\u5c0f<\/strong><\/td>\n<td>\u65e0\u9650\u5236<\/td>\n<td>\u53d7\u9650\u4e8e\u6d4f\u89c8\u5668\u5730\u5740\u680f\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td><strong>\u6570\u636e\u5b89\u5168\u6027<\/strong><\/td>\n<td>\u66f4\u5b89\u5168\uff0c\u6570\u636e\u4e0d\u4f1a\u663e\u793a\u5728\u5730\u5740\u680f\u4e2d<\/td>\n<td>\u8f83\u4e0d\u5b89\u5168\uff0c\u6570\u636e\u4f1a\u663e\u793a\u5728\u5730\u5740\u680f\u4e2d<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4f7f\u7528\u573a\u666f<\/strong><\/td>\n<td>\u63d0\u4ea4\u8868\u5355\u3001\u4e0a\u4f20\u6587\u4ef6<\/td>\n<td>\u68c0\u7d22\u6570\u636e\u3001\u5206\u9875<\/td>\n<\/tr>\n<tr>\n<td><strong>HTTP \u89c4\u8303<\/strong><\/td>\n<td><code>POST<\/code><\/td>\n<td><code>GET<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u4f7f\u7528 POST \u8bf7\u6c42\u63d0\u4ea4\u8868\u5355<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u767b\u5f55\u8868\u5355\uff0c\u5305\u542b\u7528\u6237\u540d\u548c\u5bc6\u7801\u5b57\u6bb5\u3002\u4f7f\u7528 POST \u8bf7\u6c42\u63d0\u4ea4\u8868\u5355\u7684 PHP \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;?php\nif (isset($_POST['username']) &amp;&amp; isset($_POST['password'])) {\n  \/\/ \u4ece\u8868\u5355\u4e2d\u83b7\u53d6\u6570\u636e\n  $username = $_POST['username'];\n  $password = $_POST['password'];\n\n  \/\/ \u8fde\u63a5\u5230\u6570\u636e\u5e93\u5e76\u9a8c\u8bc1\u7528\u6237\u8eab\u4efd\n  \/\/ \u7701\u7565\u6570\u636e\u5e93\u8fde\u63a5\u548c\u9a8c\u8bc1\u4ee3\u7801...\n\n  if ($user_is_authenticated) {\n    \/\/ \u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\u6210\u529f\n    header(\"Location: welcome.php\");\n  } else {\n    \/\/ \u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\u5931\u8d25\n    echo \"\u7528\u6237\u540d\u6216\u5bc6\u7801\u9519\u8bef\";\n  }\n}\n?&gt;<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u7f51\u7edc\u7f16\u7a0b\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aphp\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3 \u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300aphp\u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST\u548cGET\u8bf7\u6c42\u8be6\u89e3\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01 POST\u548cGET\u662f PHP \u7f51\u7edc\u7f16\u7a0b\u4e2d\u5e38\u89c1\u7684\u8bf7\u6c42\u65b9\u6cd5\u3002POST\u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u654f\u611f\u6216\u5927\u91cf\u6570\u636e\uff0c\u800cGET\u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u8f83\u5c11\u7684\u4e0d\u654f\u611f\u6570\u636e\u3002POST\u8bf7\u6c42\u7684\u6570\u636e\u5b89\u5168\u6027\u8f83\u9ad8\uff0c\u4e0d\u4f1a\u663e\u793a\u5728\u6d4f\u89c8\u5668\u7684\u5730\u5740\u680f\u4e2d\uff0c\u800cGET\u8bf7\u6c42\u4f1a\u663e\u793a\u5728\u5730\u5740\u680f\u4e2d\u3002 PHP \u7f51\u7edc\u7f16\u7a0b\u6307\u5357\uff1aPOST \u548c GET \u8bf7\u6c42\u8be6\u89e3 \u6982\u8ff0 \u5728 PHP \u7f51\u7edc\u7f16\u7a0b\u4e2d\uff0cPOST \u548c GET \u662f\u4e24\u79cd\u5e38\u7528\u7684\u8bf7\u6c42\u65b9\u6cd5\uff0c\u7528\u4e8e\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\u3002\u867d\u7136\u5b83\u4eec\u5728\u8bed\u6cd5\u4e0a\u76f8\u4f3c\uff0c\u4f46\u5b83\u4eec\u5728\u6570\u636e\u5904\u7406\u65b9\u5f0f\u548c\u4f7f\u7528\u573a\u666f\u4e0a\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002 POST \u8bf7\u6c42 \u5b9a\u4e49\uff1aPOST \u8bf7\u6c42\u7528\u4e8e\u53d1\u9001\u654f\u611f\u6216\u5927\u91cf\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u4e0d\u5e94\u663e\u793a\u5728\u6d4f\u89c8\u5668\u7684\u5730\u5740\u680f\u4e2d\u3002 \u8bed\u6cd5\uff1a &lt;?php $url = &#8220;https:\/\/example.com\/post_data.php&#8221;; $data = array(&#8216;username&#8217; =&gt; &#8216;john&#8217;, &#8217;email&#8217; =&gt; &#8216;john@example.com&#8217;); \/\/ \u4f7f\u7528 cURL \u53d1\u9001 POST \u8bf7\u6c42 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $response = curl_exec($ch); [&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-46952","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46952","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=46952"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46952\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}