{"id":167260,"date":"2020-01-01T09:01:19","date_gmt":"2020-01-01T01:01:19","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=167260"},"modified":"2019-12-23T11:03:27","modified_gmt":"2019-12-23T03:03:27","slug":"python-get-and","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-get-and.html","title":{"rendered":"Python\u4e4b GET\u548cPOST\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6d4f\u89c8\u5668\u5ba2\u6237\u7aef\u901a\u8fc7\u4e24\u79cd\u65b9\u6cd5\u5411\u670d\u52a1\u5668\u4f20\u9012\u4fe1\u606f\uff0c\u8fd9\u4e24\u79cd\u65b9\u6cd5\u5c31\u662f GET \u65b9\u6cd5\u548c POST \u65b9\u6cd5\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4f7f\u7528GET\u65b9\u6cd5\u4f20\u8f93\u6570\u636e<\/strong><\/div>\n

GET\u65b9\u6cd5\u53d1\u9001\u7f16\u7801\u540e\u7684\u7528\u6237\u4fe1\u606f\u5230\u670d\u52a1\u7aef\uff0c\u6570\u636e\u4fe1\u606f\u5305\u542b\u5728\u8bf7\u6c42\u9875\u9762\u7684URL\u4e0a\uff0c\u4ee5\"?\"\u53f7\u5206\u5272, \u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

http:\/\/www.test.com\/cgi-bin\/hello.py?key1=value1&key2=value2<\/pre>\n

\u6709\u5173 GET \u8bf7\u6c42\u7684\u5176\u4ed6\u4e00\u4e9b\u6ce8\u91ca\uff1a
\nGET \u8bf7\u6c42\u53ef\u88ab\u7f13\u5b58
\nGET \u8bf7\u6c42\u4fdd\u7559\u5728\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55\u4e2d
\nGET \u8bf7\u6c42\u53ef\u88ab\u6536\u85cf\u4e3a\u4e66\u7b7e
\nGET \u8bf7\u6c42\u4e0d\u5e94\u5728\u5904\u7406\u654f\u611f\u6570\u636e\u65f6\u4f7f\u7528
\nGET \u8bf7\u6c42\u6709\u957f\u5ea6\u9650\u5236
\nGET \u8bf7\u6c42\u53ea\u5e94\u5f53\u7528\u4e8e\u53d6\u56de\u6570\u636e<\/p>\n

\u7b80\u5355\u7684url\u5b9e\u4f8b\uff1aGET\u65b9\u6cd5<\/strong><\/div>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684URL\uff0c\u4f7f\u7528GET\u65b9\u6cd5\u5411hello_get.py\u7a0b\u5e8f\u53d1\u9001\u4e24\u4e2a\u53c2\u6570\uff1a<\/p>\n

\/cgi-bin\/test.py?name=\u83dc\u9e1f\u6559\u7a0b&url=http:\/\/www.runoob.com<\/pre>\n

\u4ee5\u4e0b\u4e3ahello_get.py\u6587\u4ef6\u7684\u4ee3\u7801\uff1a<\/p>\n

#!\/usr\/bin\/python3\r\n\r\n# CGI\u5904\u7406\u6a21\u5757\r\nimport cgi, cgitb \r\n\r\n# \u521b\u5efa FieldStorage \u7684\u5b9e\u4f8b\u5316\r\nform = cgi.FieldStorage() \r\n\r\n# \u83b7\u53d6\u6570\u636e\r\nsite_name = form.getvalue('name')\r\nsite_url  = form.getvalue('url')\r\n\r\nprint (\"Content-type:text\/html\")\r\nprint ()\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")<\/pre>\n

\u6587\u4ef6\u4fdd\u5b58\u540e\u4fee\u6539 hello_get.py\uff0c\u4fee\u6539\u6587\u4ef6\u6743\u9650\u4e3a 755\uff1a<\/p>\n

chmod 755 hello_get.py<\/pre>\n

\u6d4f\u89c8\u5668\u8bf7\u6c42\u8f93\u51fa\u7ed3\u679c\uff1a
\n\"\"<\/p>\n

\u7b80\u5355\u7684\u8868\u5355\u5b9e\u4f8b\uff1aGET\u65b9\u6cd5<\/strong><\/div>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u901a\u8fc7HTML\u7684\u8868\u5355\u4f7f\u7528GET\u65b9\u6cd5\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e24\u4e2a\u6570\u636e\uff0c\u63d0\u4ea4\u7684\u670d\u52a1\u5668\u811a\u672c\u540c\u6837\u662fhello_get.py\u6587\u4ef6\uff0chello_get.html \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

<!DOCTYPE html><\/span>\r\n<html><\/span>\r\n<head><\/span>\r\n<meta<\/span> charset<\/span>=<\/span>\"utf-8\"<\/span>><\/span>\r\n<title><\/span>\u83dc\u9e1f\u6559\u7a0b(runoob.com)<\/span><\/title><\/span>\r\n<\/head><\/span>\r\n<body><\/span>\r\n<form<\/span> action<\/span>=<\/span>\"\/cgi-bin\/hello_get.py\"<\/span> method<\/span>=<\/span>\"get\"<\/span>><\/span>\r\n\u7ad9\u70b9\u540d\u79f0: <\/span><input<\/span> type<\/span>=<\/span>\"text\"<\/span> name<\/span>=<\/span>\"name\"<\/span>><\/span>  <br<\/span> \/><\/span>\r\n\r\n\u7ad9\u70b9 URL: <\/span><input<\/span> type<\/span>=<\/span>\"text\"<\/span> name<\/span>=<\/span>\"url\"<\/span> \/><\/span>\r\n<input<\/span> type<\/span>=<\/span>\"submit\"<\/span> value<\/span>=<\/span>\"\u63d0\u4ea4\"<\/span> \/><\/span>\r\n<\/form><\/span>\r\n<\/body><\/span>\r\n<\/html><\/span><\/pre>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b cgi-bin \u76ee\u5f55\u53ea\u80fd\u5b58\u653e\u811a\u672c\u6587\u4ef6\uff0c\u6211\u4eec\u5c06 hello_get.html \u5b58\u50a8\u5728 test \u76ee\u5f55\u4e0b\uff0c\u4fee\u6539\u6587\u4ef6\u6743\u9650\u4e3a 755\uff1a<\/p>\n

chmod 755 hello_get.html<\/pre>\n

Gif \u6f14\u793a\u5982\u4e0b\u6240\u793a\uff1a
\n\"\"<\/p>\n

\u4f7f\u7528POST\u65b9\u6cd5\u4f20\u9012\u6570\u636e<\/strong><\/div>\n

\u4f7f\u7528POST\u65b9\u6cd5\u5411\u670d\u52a1\u5668\u4f20\u9012\u6570\u636e\u662f\u66f4\u5b89\u5168\u53ef\u9760\u7684\uff0c\u50cf\u4e00\u4e9b\u654f\u611f\u4fe1\u606f\u5982\u7528\u6237\u5bc6\u7801\u7b49\u9700\u8981\u4f7f\u7528POST\u4f20\u8f93\u6570\u636e\u3002<\/p>\n

\u4ee5\u4e0b\u540c\u6837\u662fhello_get.py \uff0c\u5b83\u4e5f\u53ef\u4ee5\u5904\u7406\u6d4f\u89c8\u5668\u63d0\u4ea4\u7684POST\u8868\u5355\u6570\u636e:<\/p>\n

#!\/usr\/bin\/python3\r\n\r\n# CGI\u5904\u7406\u6a21\u5757\r\nimport cgi, cgitb \r\n\r\n# \u521b\u5efa FieldStorage \u7684\u5b9e\u4f8b\u5316\r\nform = cgi.FieldStorage() \r\n\r\n# \u83b7\u53d6\u6570\u636e\r\nsite_name = form.getvalue('name')\r\nsite_url  = form.getvalue('url')\r\n\r\nprint (\"Content-type:text\/html\")\r\nprint ()\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\nprint (\"\")\r\n\r\nprint (\"\")<\/pre>\n

\u4ee5\u4e0b\u4e3a\u8868\u5355\u901a\u8fc7POST\u65b9\u6cd5\uff08method=\"post\"\uff09\u5411\u670d\u52a1\u5668\u811a\u672c hello_get.py \u63d0\u4ea4\u6570\u636e:<\/p>\n

<!DOCTYPE html><\/span>\r\n<html><\/span>\r\n<head><\/span>\r\n<meta<\/span> charset<\/span>=<\/span>\"utf-8\"<\/span>><\/span>\r\n<title><\/span>\u83dc\u9e1f\u6559\u7a0b(runoob.com)<\/span><\/title><\/span>\r\n<\/head><\/span>\r\n<body><\/span>\r\n<form<\/span> action<\/span>=<\/span>\"\/cgi-bin\/hello_get.py\"<\/span> method<\/span>=<\/span>\"post\"<\/span>><\/span>\r\n\u7ad9\u70b9\u540d\u79f0: <\/span><input<\/span> type<\/span>=<\/span>\"text\"<\/span> name<\/span>=<\/span>\"name\"<\/span>><\/span>  <br<\/span> \/><\/span>\r\n\r\n\u7ad9\u70b9 URL: <\/span><input<\/span> type<\/span>=<\/span>\"text\"<\/span> name<\/span>=<\/span>\"url\"<\/span> \/><\/span>\r\n<input<\/span> type<\/span>=<\/span>\"submit\"<\/span> value<\/span>=<\/span>\"\u63d0\u4ea4\"<\/span> \/><\/span>\r\n<\/form><\/span>\r\n<\/body><\/span>\r\n<\/html><\/span>\r\n<\/form><\/span><\/pre>\n

Gif \u6f14\u793a\u5982\u4e0b\u6240\u793a\uff1a
\n\"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

GET\u65b9\u6cd5\u53d1\u9001\u7f16\u7801\u540e\u7684\u7528\u6237\u4fe1\u606f\u5230\u670d\u52a1\u7aef\uff0c\u6570\u636e\u4fe1\u606f\u5305\u542b\u5728\u8bf7\u6c42\u9875\u9762\u7684URL\u4e0a\uff0c\u4ee5”?”\u53f7\u5206\u5272, \u5982\u4e0b\u6240\u793a\uff1a htt […]<\/p>\n","protected":false},"author":1470,"featured_media":167262,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-167260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/167260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=167260"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/167260\/revisions"}],"predecessor-version":[{"id":167497,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/167260\/revisions\/167497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/167262"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=167260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=167260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=167260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}