{"id":46683,"date":"2025-07-30T03:51:52","date_gmt":"2025-07-29T19:51:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46683.html"},"modified":"2025-07-30T03:51:52","modified_gmt":"2025-07-29T19:51:52","slug":"python-%e5%ba%93%e6%89%8b%e5%86%8c%ef%bc%9ahttp-server-%e8%bd%bb%e9%87%8f%e7%ba%a7-http-%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46683.html","title":{"rendered":"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757"},"content":{"rendered":"<p>http.server \u662f Python \u6807\u51c6\u5e93\u4e2d\u7528\u4e8e\u642d\u5efa\u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u7684\u6a21\u5757\u3002\u5b83\u5185\u7f6e\u4e8e Python \u4e2d&#xff0c;\u65e0\u9700\u989d\u5916\u5b89\u88c5&#xff0c;\u9002\u7528\u4e8e\u5feb\u901f\u6d4b\u8bd5\u7f51\u9875\u3001\u5171\u4eab\u672c\u5730\u6587\u4ef6\u6216\u8fdb\u884c\u57fa\u672c\u7684 Web \u670d\u52a1\u8c03\u8bd5\u3002<\/p>\n<p>\u5e38\u89c1\u5e94\u7528\u573a\u666f&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;\u672c\u5730\u76ee\u5f55\u5171\u4eab&#xff1a;\u5feb\u901f\u5728\u5c40\u57df\u7f51\u4e2d\u5171\u4eab\u6587\u4ef6\u3002<\/p>\n<p>&#xff08;2&#xff09; Web \u9875\u9762\u8c03\u8bd5&#xff1a;\u65e0\u9700\u5b89\u88c5 Web \u6846\u67b6\u5373\u53ef\u6d4b\u8bd5 HTML\/JS\/CSS\u3002<\/p>\n<p>&#xff08;3&#xff09;\u524d\u7aef\u9759\u6001\u9875\u9762\u90e8\u7f72\u6f14\u793a\u3002<\/p>\n<p>&#xff08;4&#xff09;\u6a21\u62df\u670d\u52a1\u63a5\u53e3\u8fdb\u884c\u540e\u7aef\u8054\u8c03\u3002<\/p>\n<p>&#xff08;5&#xff09;Python \u7f51\u7edc\u7f16\u7a0b\u6559\u5b66\u5b9e\u8df5\u3002<\/p>\n<p style=\"text-align: center\">\u25c6\u00a0\u00a0\u25c6\u00a0\u00a0\u25c6<\/p>\n<p style=\"text-align: center\">\u6838\u5fc3\u6982\u5ff5<\/p>\n<p>1\u3001HTTPServer <\/p>\n<p>\u57fa\u4e8e socketserver.TCPServer \u7684 HTTP \u670d\u52a1\u7c7b&#xff0c;\u7528\u4e8e\u76d1\u542c\u8bf7\u6c42\u5e76\u5206\u53d1\u5904\u7406\u3002<\/p>\n<p>2\u3001BaseHTTPRequestHandler <\/p>\n<p>\u6240\u6709\u8bf7\u6c42\u5904\u7406\u7c7b\u7684\u57fa\u7c7b&#xff0c;\u5b9a\u4e49\u4e86\u5982\u4f55\u54cd\u5e94 GET\u3001POST\u3001HEAD \u7b49\u8bf7\u6c42\u3002<\/p>\n<p>3\u3001SimpleHTTPRequestHandler <\/p>\n<p>\u5904\u7406 GET \u548c HEAD \u8bf7\u6c42&#xff0c;\u81ea\u52a8\u63d0\u4f9b\u9759\u6001\u76ee\u5f55\u6d4f\u89c8\u4e0e\u6587\u4ef6\u4e0b\u8f7d\u529f\u80fd\u3002<\/p>\n<p>4\u3001\u547d\u4ee4\u884c\u8fd0\u884c\u65b9\u5f0f <\/p>\n<p>\u4f7f\u7528 python -m http.server \u5feb\u901f\u542f\u52a8\u670d\u52a1&#xff0c;\u65e0\u9700\u7f16\u7a0b\u3002<\/p>\n<p>5\u3001wfile \/ rfile <\/p>\n<p>\u5ba2\u6237\u7aef\u901a\u4fe1\u7684\u8f93\u51fa \/ \u8f93\u5165\u6d41\u5bf9\u8c61&#xff0c;\u7528\u4e8e\u8bfb\u53d6\u8bf7\u6c42\u6570\u636e\u548c\u5199\u5165\u54cd\u5e94\u6570\u636e\u3002<\/p>\n<p style=\"text-align: center\">\u25c6\u00a0\u00a0\u25c6\u00a0\u00a0\u25c6<\/p>\n<p style=\"text-align: center\">\u5e94\u7528\u4e3e\u4f8b<\/p>\n<p>\u4f8b 1&#xff1a;\u547d\u4ee4\u884c\u5feb\u901f\u542f\u52a8\u672c\u5730 HTTP \u6587\u4ef6\u670d\u52a1<\/p>\n<p> # \u542f\u52a8\u672c\u5730 HTTP \u670d\u52a1&#xff08;\u9ed8\u8ba4\u7aef\u53e3 8000&#xff09;python\u00a0-m http.server<br \/>\n# \u6307\u5b9a\u7aef\u53e3\u4e0e\u76ee\u5f55python\u00a0-m http.server\u00a08888\u00a0&#8211;directory .\/public<\/p>\n<p style=\"text-align: justify\">\u4f8b 2&#xff1a;\u81ea\u5b9a\u4e49 GET \u8bf7\u6c42\u5904\u7406<\/p>\n<p> from\u00a0http.server\u00a0import\u00a0HTTPServer, BaseHTTPRequestHandler<br \/>\nclass\u00a0MyHandler(BaseHTTPRequestHandler):\u00a0 \u00a0\u00a0def\u00a0do_GET(self):\u00a0 \u00a0 \u00a0 \u00a0 self.send_response(200)\u00a0 \u00a0 \u00a0 \u00a0 self.send_header(&#034;Content-type&#034;,\u00a0&#034;text\/plain; charset&#061;utf-8&#034;)\u00a0 \u00a0 \u00a0 \u00a0 self.end_headers()\u00a0 \u00a0 \u00a0 \u00a0 self.wfile.write(b&#034;Hello from Python HTTP server!&#034;)<br \/>\nserver &#061; HTTPServer((&#034;localhost&#034;,\u00a08080), MyHandler)server.serve_forever()<\/p>\n<p style=\"text-align: justify\">\u4f8b 3&#xff1a;\u542f\u7528\u591a\u7ebf\u7a0b\u5904\u7406&#xff08;\u9002\u5408\u5e76\u53d1\u8c03\u8bd5&#xff09;<\/p>\n<p> from\u00a0http.server\u00a0import\u00a0HTTPServer, SimpleHTTPRequestHandlerfrom\u00a0socketserver\u00a0import\u00a0ThreadingMixIn<br \/>\nclass\u00a0ThreadingHTTPServer(ThreadingMixIn, HTTPServer):\u00a0 \u00a0 daemon_threads &#061;\u00a0True<br \/>\nserver &#061; ThreadingHTTPServer((&#034;0.0.0.0&#034;,\u00a08000), SimpleHTTPRequestHandler)print(&#034;Serving at http:\/\/0.0.0.0:8000&#034;)server.serve_forever()<\/p>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<p>\u672c\u793a\u4f8b\u652f\u6301\u591a\u4eba\u6216\u591a\u4e2a\u6d4f\u89c8\u5668\u540c\u65f6\u8bbf\u95ee\u65f6&#xff0c;\u670d\u52a1\u5668\u80fd\u5e76\u53d1\u54cd\u5e94&#xff0c;\u4e0d\u4f1a\u56e0\u67d0\u4e00\u4e2a\u8bf7\u6c42\u963b\u585e\u5176\u4ed6\u8bf7\u6c42\u3002<\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165&#xff1a;<\/p>\n<p> http:\/\/localhost:8000\/<\/p>\n<p>\u6216\u4f7f\u7528\u540c\u4e00\u5c40\u57df\u7f51\u4e2d\u7684\u8bbe\u5907\u8bbf\u95ee&#xff1a;<\/p>\n<p> http:\/\/&lt;\u4f60\u7535\u8111\u7684IP&gt;:8000\/<\/p>\n<p>\u4f8b 4&#xff1a;\u6dfb\u52a0 POST \u8bf7\u6c42\u5904\u7406&#xff08;\u57fa\u7840\u8868\u5355\u63a5\u6536&#xff09;<\/p>\n<p> from\u00a0http.server\u00a0import\u00a0BaseHTTPRequestHandler, HTTPServer<br \/>\nclass\u00a0MyHandler(BaseHTTPRequestHandler):\u00a0 \u00a0\u00a0def\u00a0do_GET(self):\u00a0 \u00a0 \u00a0 \u00a0 self.send_response(200) \u00a0# \u8fd4\u56de\u72b6\u6001\u7801 200&#xff08;\u6210\u529f&#xff09;\u00a0 \u00a0 \u00a0 \u00a0 self.send_header(&#034;Content-type&#034;,\u00a0&#034;text\/html&#034;) \u00a0# \u8bbe\u7f6e Content-Type \u54cd\u5e94\u5934\u00a0 \u00a0 \u00a0 \u00a0 self.end_headers() \u00a0# \u54cd\u5e94\u5934\u7ed3\u675f\u00a0 \u00a0 \u00a0 \u00a0 self.wfile.write(b&#034;&lt;h1&gt;Hello, mediaTEA!&lt;\/h1&gt;&#034;) \u00a0# \u54cd\u5e94\u6b63\u6587&#xff08;\u5fc5\u987b\u662f\u5b57\u8282\u4e32&#xff09;<br \/>\n# \u521b\u5efa HTTP \u670d\u52a1\u5668&#xff0c;\u7ed1\u5b9a\u5730\u5740\u4e3a localhost:8000server &#061; HTTPServer((&#034;localhost&#034;,\u00a08000), MyHandler)<br \/>\nprint(&#034;Custom HTTP server running at http:\/\/localhost:8000&#034;)<br \/>\n# \u542f\u52a8\u670d\u52a1\u5668&#xff08;\u963b\u585e\u4e3b\u7ebf\u7a0b&#xff09;server.serve_forever()<\/p>\n<p>\u4f8b 5&#xff1a;\u8fd4\u56de JSON \u54cd\u5e94&#xff08;\u63a5\u53e3\u8c03\u8bd5\u6a21\u62df&#xff09;<\/p>\n<p> import\u00a0jsonfrom\u00a0http.server\u00a0import\u00a0BaseHTTPRequestHandler, HTTPServer<br \/>\nclass\u00a0JsonHandler(BaseHTTPRequestHandler):\u00a0 \u00a0\u00a0def\u00a0do_GET(self):\u00a0 \u00a0 \u00a0 \u00a0 data &#061; {&#034;status&#034;:\u00a0&#034;ok&#034;,\u00a0&#034;message&#034;:\u00a0&#034;This is JSON&#034;}\u00a0 \u00a0 \u00a0 \u00a0 self.send_response(200)\u00a0 \u00a0 \u00a0 \u00a0 self.send_header(&#034;Content-type&#034;,\u00a0&#034;application\/json&#034;)\u00a0 \u00a0 \u00a0 \u00a0 self.end_headers()\u00a0 \u00a0 \u00a0 \u00a0 self.wfile.write(json.dumps(data).encode(&#034;utf-8&#034;))<br \/>\nserver &#061; HTTPServer((&#034;localhost&#034;,\u00a08001), JsonHandler)server.serve_forever()<\/p>\n<p style=\"text-align: center\">\u25c6\u00a0\u00a0\u25c6\u00a0\u00a0\u25c6<\/p>\n<p style=\"text-align: center\">\u5e38\u7528\u51fd\u6570\u901f\u89c8<\/p>\n<p>BaseHTTPRequestHandler.end_headers()<\/p>\n<p>\u7ed3\u675f\u54cd\u5e94\u5934\u7684\u53d1\u9001&#xff0c;\u51c6\u5907\u53d1\u9001\u6b63\u6587\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;\u65e0<\/p>\n<p>\u8fd4\u56de&#xff1a;\u65e0<\/p>\n<p>BaseHTTPRequestHandler.send_header(key,\u00a0value)<\/p>\n<p>\u53d1\u9001\u4e00\u6761 HTTP \u54cd\u5e94\u5934\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;<\/p>\n<p>key&#xff1a;\u5b57\u7b26\u4e32&#xff0c;\u5934\u5b57\u6bb5\u540d&#xff0c;\u5982 &#034;Content-type&#034;<\/p>\n<p>value&#xff1a;\u5b57\u7b26\u4e32&#xff0c;\u5b57\u6bb5\u503c&#xff0c;\u5982 &#034;text\/html&#034;<\/p>\n<p>\u8fd4\u56de&#xff1a;\u65e0<\/p>\n<p>BaseHTTPRequestHandler.send_response(code,\u00a0message&#061;None)<\/p>\n<p>\u53d1\u9001\u72b6\u6001\u7801\u4e0e\u53ef\u9009\u7684\u72b6\u6001\u63cf\u8ff0\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;<\/p>\n<p>code&#xff1a;\u6574\u6570&#xff0c;HTTP \u72b6\u6001\u7801&#xff08;\u5982 200\u3001404&#xff09;<\/p>\n<p>message&#xff1a;\u5b57\u7b26\u4e32&#xff0c;\u53ef\u9009\u72b6\u6001\u8bf4\u660e<\/p>\n<p>\u8fd4\u56de&#xff1a;\u65e0<\/p>\n<p>HTTPServer(address,\u00a0handler)<\/p>\n<p>\u521b\u5efa HTTP \u670d\u52a1\u5668\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;<\/p>\n<p>address&#xff1a;\u5143\u7ec4 (host, port)<\/p>\n<p>handler&#xff1a;\u5904\u7406\u7c7b&#xff08;\u7ee7\u627f\u81ea BaseHTTPRequestHandler&#xff09;<\/p>\n<p>\u8fd4\u56de&#xff1a;HTTPServer \u5b9e\u4f8b<\/p>\n<p>HTTPServer.serve_forever()<\/p>\n<p>\u6301\u7eed\u8fd0\u884c\u670d\u52a1\u5668\u5e76\u54cd\u5e94\u8bf7\u6c42\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;\u65e0<\/p>\n<p>\u8fd4\u56de&#xff1a;\u65e0&#xff08;\u963b\u585e\u8fd0\u884c&#xff09;<\/p>\n<p>wfile.write(data)<\/p>\n<p>\u53d1\u9001\u54cd\u5e94\u4f53&#xff08;\u4e8c\u8fdb\u5236\u6570\u636e&#xff09;\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;<\/p>\n<p>data&#xff1a;\u5b57\u8282\u4e32&#xff08;\u9700\u7528 b&#034;&#8230;&#034; \u683c\u5f0f&#xff09;<\/p>\n<p>\u8fd4\u56de&#xff1a;\u5199\u5165\u7684\u5b57\u8282\u6570<\/p>\n<p style=\"text-align: center\">\u25c6\u00a0\u00a0\u25c6\u00a0\u00a0\u25c6<\/p>\n<p style=\"text-align: center\">\u8865\u5145\u8bf4\u660e<\/p>\n<p>1\u3001\u9ed8\u8ba4\u4f7f\u7528\u7684\u662f\u5355\u7ebf\u7a0b\u670d\u52a1&#xff0c;\u5728\u5e76\u53d1\u6d4b\u8bd5\u4e2d\u53ef\u80fd\u4f1a\u963b\u585e\u3002\u53ef\u901a\u8fc7 socketserver.ThreadingMixIn \u5b9e\u73b0\u591a\u7ebf\u7a0b\u3002<\/p>\n<p>2\u3001\u8be5\u6a21\u5757\u4ec5\u5904\u7406\u9759\u6001\u5185\u5bb9&#xff0c;\u4e0d\u5177\u5907\u8def\u7531\u3001\u6a21\u677f\u3001\u8ba4\u8bc1\u7b49\u529f\u80fd\u3002<\/p>\n<p>3\u3001\u53ef\u901a\u8fc7\u91cd\u5199 do_GET()\u3001do_POST() \u7b49\u65b9\u6cd5\u81ea\u5b9a\u4e49\u8bf7\u6c42\u884c\u4e3a\u3002<\/p>\n<p>4\u3001\u914d\u5408 subprocess \u8c03\u7528&#xff0c;\u53ef\u5c06\u5176\u96c6\u6210\u5230\u81ea\u52a8\u5316\u6d4b\u8bd5\u6d41\u7a0b\u4e2d\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" alt=\"\u56fe\u7247\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729195149-68892655de0f6.png\" \/><\/p>\n<p style=\"text-align: center\">\u201c\u70b9\u8d5e\u6709\u7f8e\u610f&#xff0c;\u8d5e\u8d4f\u662f\u9f13\u52b1\u201d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u5b83\u5185\u7f6e\u4e8e Python \u4e2d\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\uff0c\u9002\u7528\u4e8e\u5feb\u901f\u6d4b\u8bd5\u7f51\u9875\u3001\u5171\u4eab\u672c\u5730\u6587\u4ef6\u6216\u8fdb\u884c\u57fa\u672c\u7684 Web \u670d\u52a1\u8c03\u8bd5\u3002\u57fa\u4e8e socketserver.TCPServer \u7684 HTTP \u670d\u52a1\u7c7b\uff0c\u7528\u4e8e\u76d1\u542c\u8bf7\u6c42\u5e76\u5206\u53d1\u5904\u7406\u3002\u591a\u4eba\u6216\u591a\u4e2a\u6d4f\u89c8\u5668\u540c\u65f6\u8bbf\u95ee\u65f6\uff0c\u670d\u52a1\u5668\u80fd\u5e76\u53d1\u54cd\u5e94\uff0c\u4e0d\u4f1a\u56e0\u67d0\u4e00\u4e2a\u8bf7\u6c42\u963b\u585e\u5176\u4ed6\u8bf7\u6c42\u30023\u3001\u53ef\u901a\u8fc7\u91cd\u5199 do_GET()\u3001do_POST() \u7b49\u65b9\u6cd5\u81ea\u5b9a\u4e49\u8bf7\u6c42\u884c\u4e3a\u3002\u6240\u6709\u8bf7\u6c42\u5904\u7406\u7c7b\u7684\u57fa\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5982\u4f55\u54cd\u5e94 GET\u3001POST\u3001HEAD \u7b49\u8bf7\u6c42\u30022\u3001\u8be5\u6a21\u5757\u4ec5\u5904\u7406\u9759\u6001\u5185\u5bb9\uff0c\u4e0d\u5177\u5907\u8def\u7531\u3001\u6a21\u677f\u3001\u8ba4\u8bc1\u7b49\u529f\u80fd\u3002<\/p>\n","protected":false},"author":2,"featured_media":46682,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[151,81,190,43,191],"topic":[],"class_list":["post-46683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-http","tag-python","tag-190","tag-43","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/46683.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u5b83\u5185\u7f6e\u4e8e Python \u4e2d\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\uff0c\u9002\u7528\u4e8e\u5feb\u901f\u6d4b\u8bd5\u7f51\u9875\u3001\u5171\u4eab\u672c\u5730\u6587\u4ef6\u6216\u8fdb\u884c\u57fa\u672c\u7684 Web \u670d\u52a1\u8c03\u8bd5\u3002\u57fa\u4e8e socketserver.TCPServer \u7684 HTTP \u670d\u52a1\u7c7b\uff0c\u7528\u4e8e\u76d1\u542c\u8bf7\u6c42\u5e76\u5206\u53d1\u5904\u7406\u3002\u591a\u4eba\u6216\u591a\u4e2a\u6d4f\u89c8\u5668\u540c\u65f6\u8bbf\u95ee\u65f6\uff0c\u670d\u52a1\u5668\u80fd\u5e76\u53d1\u54cd\u5e94\uff0c\u4e0d\u4f1a\u56e0\u67d0\u4e00\u4e2a\u8bf7\u6c42\u963b\u585e\u5176\u4ed6\u8bf7\u6c42\u30023\u3001\u53ef\u901a\u8fc7\u91cd\u5199 do_GET()\u3001do_POST() \u7b49\u65b9\u6cd5\u81ea\u5b9a\u4e49\u8bf7\u6c42\u884c\u4e3a\u3002\u6240\u6709\u8bf7\u6c42\u5904\u7406\u7c7b\u7684\u57fa\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5982\u4f55\u54cd\u5e94 GET\u3001POST\u3001HEAD \u7b49\u8bf7\u6c42\u30022\u3001\u8be5\u6a21\u5757\u4ec5\u5904\u7406\u9759\u6001\u5185\u5bb9\uff0c\u4e0d\u5177\u5907\u8def\u7531\u3001\u6a21\u677f\u3001\u8ba4\u8bc1\u7b49\u529f\u80fd\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46683.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T19:51:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729195149-68892655de0f6.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46683.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46683.html\",\"name\":\"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T19:51:52+00:00\",\"dateModified\":\"2025-07-29T19:51:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46683.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46683.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46683.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/46683.html","og_locale":"zh_CN","og_type":"article","og_title":"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u5b83\u5185\u7f6e\u4e8e Python \u4e2d\uff0c\u65e0\u9700\u989d\u5916\u5b89\u88c5\uff0c\u9002\u7528\u4e8e\u5feb\u901f\u6d4b\u8bd5\u7f51\u9875\u3001\u5171\u4eab\u672c\u5730\u6587\u4ef6\u6216\u8fdb\u884c\u57fa\u672c\u7684 Web \u670d\u52a1\u8c03\u8bd5\u3002\u57fa\u4e8e socketserver.TCPServer \u7684 HTTP \u670d\u52a1\u7c7b\uff0c\u7528\u4e8e\u76d1\u542c\u8bf7\u6c42\u5e76\u5206\u53d1\u5904\u7406\u3002\u591a\u4eba\u6216\u591a\u4e2a\u6d4f\u89c8\u5668\u540c\u65f6\u8bbf\u95ee\u65f6\uff0c\u670d\u52a1\u5668\u80fd\u5e76\u53d1\u54cd\u5e94\uff0c\u4e0d\u4f1a\u56e0\u67d0\u4e00\u4e2a\u8bf7\u6c42\u963b\u585e\u5176\u4ed6\u8bf7\u6c42\u30023\u3001\u53ef\u901a\u8fc7\u91cd\u5199 do_GET()\u3001do_POST() \u7b49\u65b9\u6cd5\u81ea\u5b9a\u4e49\u8bf7\u6c42\u884c\u4e3a\u3002\u6240\u6709\u8bf7\u6c42\u5904\u7406\u7c7b\u7684\u57fa\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5982\u4f55\u54cd\u5e94 GET\u3001POST\u3001HEAD \u7b49\u8bf7\u6c42\u30022\u3001\u8be5\u6a21\u5757\u4ec5\u5904\u7406\u9759\u6001\u5185\u5bb9\uff0c\u4e0d\u5177\u5907\u8def\u7531\u3001\u6a21\u677f\u3001\u8ba4\u8bc1\u7b49\u529f\u80fd\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/46683.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T19:51:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729195149-68892655de0f6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46683.html","url":"https:\/\/www.wsisp.com\/helps\/46683.html","name":"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T19:51:52+00:00","dateModified":"2025-07-29T19:51:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46683.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46683.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46683.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python \u5e93\u624b\u518c\uff1ahttp.server \u8f7b\u91cf\u7ea7 HTTP \u670d\u52a1\u5668\u6a21\u5757"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=46683"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46683\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/46682"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46683"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}