{"id":81488,"date":"2026-07-25T02:36:20","date_gmt":"2026-07-24T18:36:20","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/81488.html"},"modified":"2026-07-25T02:36:20","modified_gmt":"2026-07-24T18:36:20","slug":"%e3%80%90linux%e4%b9%8b%e6%97%85%e3%80%91http-%e5%8d%8f%e8%ae%ae%e8%a7%a3%e6%9e%90%ef%bc%9a%e4%bb%8e%e8%af%b7%e6%b1%82%e6%a0%bc%e5%bc%8f%e5%88%b0%e6%9e%84%e5%bb%ba-web-%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/81488.html","title":{"rendered":"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183605-6a63b09544017.png\" alt=\"QQ20260622-233105\" \/> <\/p>\n<h4><font color=\"red\">\u8bf7\u541b\u6d4f\u89c8<\/font><\/h4>\n<ul>\n<li>\n<ul>\n<li>\u524d\u8a00<\/li>\n<li>\u4e00\u3001HTTP \u534f\u8bae\u6982\u8ff0<\/li>\n<li>\n<ul>\n<li>1.1 \u8ba4\u8bc6 URL<\/li>\n<li>1.2 urlencode \u4e0e urldecode<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c\u3001HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u683c\u5f0f<\/li>\n<li>\n<ul>\n<li>2.1 \u8bf7\u6c42\u683c\u5f0f<\/li>\n<li>2.2 \u54cd\u5e94\u683c\u5f0f<\/li>\n<li>2.3 \u624b\u5de5\u9a8c\u8bc1&#xff1a;\u7528 netcat \u53d1\u9001 HTTP \u8bf7\u6c42<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001HTTP \u65b9\u6cd5<\/li>\n<li>\n<ul>\n<li>3.1 GET \u4e0e POST \u7684\u6838\u5fc3\u533a\u522b<\/li>\n<li>3.2 \u8868\u5355\u63d0\u4ea4&#xff1a;GET \u8fd8\u662f POST<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001HTTP \u72b6\u6001\u7801\u4e0e\u91cd\u5b9a\u5411<\/li>\n<li>\n<ul>\n<li>4.1 \u72b6\u6001\u7801\u901f\u67e5<\/li>\n<li>4.2 \u91cd\u5b9a\u5411\u7684\u5e95\u5c42\u673a\u5236<\/li>\n<\/ul>\n<\/li>\n<li>\u4e94\u3001HTTP \u5e38\u89c1 Header<\/li>\n<li>\n<ul>\n<li>5.1 \u6838\u5fc3 Header \u4e00\u89c8<\/li>\n<li>5.2 \u6709\u8da3\u7684 User-Agent \u5386\u53f2<\/li>\n<li>5.3 Connection \u5b57\u6bb5\u4e0e\u957f\u8fde\u63a5\u7684\u5de5\u7a0b\u610f\u4e49<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001\u5b9e\u73b0 HTTP \u670d\u52a1\u5668\u2014\u2014\u4ece Hello World \u5230\u5b8c\u6574 Web \u540e\u7aef<\/li>\n<li>\n<ul>\n<li>6.1 Hello World\u2014\u2014\u6700\u5c0f\u53ef\u884c\u7248\u672c<\/li>\n<li>6.2 \u6269\u5c55\u4e00&#xff1a;\u652f\u6301\u8bf7\u6c42\u8def\u5f84\u89e3\u6790\u548c\u9759\u6001\u6587\u4ef6\u8fd4\u56de<\/li>\n<li>6.3 \u6269\u5c55\u4e8c&#xff1a;\u652f\u6301 POST \u8bf7\u6c42\u2014\u2014\u89e3\u6790\u8868\u5355\u548c JSON<\/li>\n<li>6.4 \u6269\u5c55\u4e09&#xff1a;\u5b8c\u6574\u7684 HTTP \u8bf7\u6c42\u54cd\u5e94\u6d41\u6c34\u7ebf<\/li>\n<\/ul>\n<\/li>\n<li>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u907f\u5751\u6307\u5357<\/li>\n<li>\n<ul>\n<li>7.1 Header \u548c Body \u4e4b\u95f4\u7684\u7a7a\u884c\u4e22\u5931<\/li>\n<li>7.2 Content-Length \u4e0e\u5b9e\u9645 Body \u957f\u5ea6\u4e0d\u5339\u914d<\/li>\n<li>7.3 \u6d4f\u89c8\u5668\u591a\u53d1\u51fa\u4e00\u4e2a \/favicon.ico \u8bf7\u6c42<\/li>\n<li>7.4 URL \u8def\u5f84\u5305\u542b &#096;..&#096; \u5bfc\u81f4\u76ee\u5f55\u7a7f\u8d8a<\/li>\n<\/ul>\n<\/li>\n<li>\u516b\u3001MIME \u7c7b\u578b\u4e0e Content-Type<\/li>\n<li>\n<ul>\n<li>8.1 \u4e3a\u4ec0\u4e48\u9700\u8981 Content-Type<\/li>\n<li>8.2 \u5e38\u89c1\u7684 Content-Type \u573a\u666f\u5bf9\u7167<\/li>\n<\/ul>\n<\/li>\n<li>\u4e5d\u3001\u6d4f\u89c8\u5668\u7f13\u5b58\u673a\u5236\u2014\u2014304 Not Modified \u7684\u539f\u7406<\/li>\n<li>\n<ul>\n<li>9.1 \u57fa\u4e8e\u65f6\u95f4\u7684\u7f13\u5b58&#xff1a;Last-Modified &#043; If-Modified-Since<\/li>\n<li>9.2 \u57fa\u4e8e\u5185\u5bb9\u7684\u7f13\u5b58&#xff1a;ETag &#043; If-None-Match<\/li>\n<li>9.3 Cache-Control&#xff1a;\u8ba9\u6d4f\u89c8\u5668\u8df3\u8fc7&#034;\u9a8c\u8bc1&#034;\u6b65\u9aa4<\/li>\n<\/ul>\n<\/li>\n<li>\u603b\u7ed3<\/li>\n<li>\n<ul>\n<li>\u52a8\u624b\u8bd5\u8bd5<\/li>\n<\/ul>\n<\/li>\n<li>\u9644\u5f55&#xff1a;HTTP \u7248\u672c\u6f14\u8fdb\u7b80\u53f2<\/li>\n<li>\u5c3e\u58f0<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u524d\u8a00<\/h3>\n<p>\u4e4b\u524d\u6211\u4eec\u5b9a\u4e49\u4e86\u79c1\u6709\u5e94\u7528\u5c42\u534f\u8bae&#xff0c;\u4f53\u4f1a\u4e86 Encode\/Decode &#043; \u5e8f\u5217\u5316\/\u53cd\u5e8f\u5217\u5316 \u7684\u8bbe\u8ba1\u6a21\u5f0f\u3002\u4f46\u5b9e\u9645\u7684\u4e92\u8054\u7f51\u4e16\u754c\u4e2d&#xff0c;HTTP \u624d\u662f\u5e94\u7528\u5c42\u534f\u8bae\u7684\u4e8b\u5b9e\u6807\u51c6\u2014\u2014\u5b83\u7edf\u4e00\u4e86\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u901a\u4fe1\u89c4\u5219&#xff0c;\u4e5f\u7edf\u4e00\u4e86\u6211\u4eec\u4f7f\u7528\u7684\u51e0\u4e4e\u6bcf\u4e00\u4e2a Web API\u3002\u7406\u89e3\u4e86 HTTP \u7684\u5e95\u5c42\u683c\u5f0f&#xff0c;\u518d\u53bb\u770b Flask\u3001Spring Boot\u3001Express \u8fd9\u4e9b Web \u6846\u67b6&#xff0c;\u4f60\u4f1a\u53d1\u73b0\u5b83\u4eec\u4e0d\u8fc7\u662f\u5728 HTTP \u62a5\u6587\u4e0a\u9762\u5305\u4e86\u4e00\u5c42\u4fbf\u5229\u7684 API\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ece HTTP \u534f\u8bae\u7684\u8bf7\u6c42\/\u54cd\u5e94\u683c\u5f0f\u51fa\u53d1&#xff0c;\u9010\u4e00\u62c6\u89e3 URL\u3001\u8bf7\u6c42\u65b9\u6cd5\u3001\u72b6\u6001\u7801\u3001\u5e38\u7528 Header\u3001Connection \u957f\u8fde\u63a5\u7b49\u6838\u5fc3\u6982\u5ff5&#xff0c;\u4eb2\u624b\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 GET \u548c POST \u7684\u6700\u7b80 HTTP \u670d\u52a1\u5668&#xff0c;\u5e76\u9010\u6b65\u6269\u5c55\u4e3a\u80fd\u8fd4\u56de\u9759\u6001\u6587\u4ef6\u3001\u89e3\u6790\u8868\u5355\u6570\u636e\u7684\u529f\u80fd\u5b8c\u5907\u7684 Web \u670d\u52a1\u5668\u3002\u8bfb\u5b8c\u672c\u6587&#xff0c;\u4f60\u5c06\u5f7b\u5e95\u7406\u89e3 HTTP \u534f\u8bae\u7684\u5e95\u5c42\u7ea6\u5b9a&#xff0c;\u5e76\u80fd\u4ece\u5934\u5199\u51fa\u4e00\u4e2a\u53ef\u88ab\u6d4f\u89c8\u5668\u8bbf\u95ee\u7684\u771f\u5b9e Web \u540e\u7aef\u3002<\/p>\n<h3>\u4e00\u3001HTTP \u534f\u8bae\u6982\u8ff0<\/h3>\n<p>HTTP&#xff08;HyperText Transfer Protocol&#xff0c;\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae&#xff09; \u5b9a\u4e49\u4e86\u5ba2\u6237\u7aef&#xff08;\u901a\u5e38\u662f\u6d4f\u89c8\u5668&#xff09;\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u901a\u4fe1\u683c\u5f0f\u3002\u5b83\u662f\u65e0\u8fde\u63a5\u3001\u65e0\u72b6\u6001\u7684\u534f\u8bae\u2014\u2014\u6bcf\u6b21\u8bf7\u6c42\u72ec\u7acb&#xff0c;\u670d\u52a1\u5668\u4e0d\u4fdd\u7559\u5ba2\u6237\u7aef\u7684\u4e0a\u4e00\u6b21\u72b6\u6001&#xff08;\u4f1a\u8bdd\u529f\u80fd\u7531 Cookie \u7b49\u673a\u5236\u5728\u4e0a\u5c42\u5b9e\u73b0&#xff09;\u3002<\/p>\n<p>HTTP \u534f\u8bae\u662f\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u901a\u4fe1\u7684\u57fa\u7840\u3002\u5ba2\u6237\u7aef\u901a\u8fc7 HTTP \u534f\u8bae\u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u540e\u5904\u7406\u5e76\u8fd4\u56de\u54cd\u5e94\u3002\u8fd9\u79cd&#034;\u4e00\u6b21\u8bf7\u6c42-\u4e00\u6b21\u54cd\u5e94&#034;\u7684\u6a21\u5f0f&#xff0c;\u6784\u6210\u4e86\u73b0\u4ee3\u4e92\u8054\u7f51\u5e94\u7528\u7684\u5168\u90e8\u4ea4\u4e92\u57fa\u7840\u3002<\/p>\n<p>HTTP \u672c\u8d28\u4e0a\u5c31\u662f\u4e0a\u4e00\u7bc7\u81ea\u5b9a\u4e49\u534f\u8bae\u7684&#034;\u6807\u51c6\u5316\u7248\u672c&#034;&#xff1a;\u8bf7\u6c42 &#061; \u9996\u884c &#043; Header &#043; Body&#xff0c;\u54cd\u5e94\u4e5f\u662f\u4e00\u6837\u3002\u7406\u89e3\u4e86\u4e0a\u4e00\u7bc7\u7684 Encode\/Decode \u6a21\u5f0f&#xff0c;HTTP \u53ea\u662f\u628a\u62a5\u6587\u683c\u5f0f\u6362\u6210\u4e86\u6807\u51c6\u7684\u5199\u6cd5\u2014\u2014\u7528 \\\\r\\\\n \u5206\u9694\u3001\u7528 Content-Length \u786e\u5b9a Body \u957f\u5ea6\u3002<\/p>\n<p>HTTP \u4e4b\u6240\u4ee5\u80fd\u6210\u4e3a\u4e92\u8054\u7f51\u7684&#034;\u666e\u901a\u8bdd&#034;&#xff0c;\u5173\u952e\u5728\u4e8e\u5b83\u627e\u5230\u4e86\u7b80\u5355\u6027\u548c\u8868\u8fbe\u529b\u4e4b\u95f4\u7684\u6700\u4f73\u5e73\u8861\u70b9\u3002\u534f\u8bae\u8bbe\u8ba1\u8005\u9762\u4e34\u4e00\u4e2a\u7ecf\u5178\u77db\u76fe&#xff1a;\u592a\u7b80\u5355\u4e86\u8868\u8fbe\u4e0d\u4e86\u590d\u6742\u9700\u6c42&#xff08;\u5982\u65e9\u671f\u7684 Gopher \u534f\u8bae\u53ea\u80fd\u6d4f\u89c8\u7eaf\u6587\u672c\u83dc\u5355&#xff09;&#xff0c;\u592a\u590d\u6742\u4e86\u5b9e\u73b0\u95e8\u69db\u592a\u9ad8&#xff08;\u5982 CORBA \u548c SOAP&#xff0c;\u6700\u7ec8\u88ab RESTful JSON \u53d6\u4ee3&#xff09;\u3002HTTP \u7684\u9009\u62e9\u662f&#xff1a;\u7528\u7eaf\u6587\u672c\u9996\u884c\u548c Header \u8868\u8fbe\u5143\u4fe1\u606f&#xff08;\u4eba\u7c7b\u53ef\u8bfb\u3001\u65b9\u4fbf\u8c03\u8bd5&#xff09;&#xff0c;\u7528 Content-Length \u7cbe\u786e\u754c\u5b9a Body \u957f\u5ea6&#xff08;\u89e3\u51b3\u7c98\u5305&#xff09;&#xff0c;Body \u672c\u8eab\u5219\u53ef\u4ee5\u662f\u4efb\u610f\u4e8c\u8fdb\u5236\u6570\u636e&#xff08;\u4e0d\u9650\u5236\u5185\u5bb9\u7c7b\u578b&#xff09;\u3002\u8fd9\u4e09\u5c42\u8bbe\u8ba1\u8ba9 HTTP \u540c\u65f6\u670d\u52a1\u4e86\u9759\u6001\u7f51\u9875\u3001API \u8c03\u7528\u3001\u6587\u4ef6\u4e0a\u4f20\u3001\u89c6\u9891\u6d41\u548c WebSocket \u53cc\u5411\u901a\u4fe1\u2014\u2014\u540c\u4e00\u5957\u534f\u8bae&#xff0c;\u8d1f\u8f7d\u4e86\u4e92\u8054\u7f51 80% \u4ee5\u4e0a\u7684\u6d41\u91cf\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u4e8b\u5b9e\u662f&#xff1a;HTTP \u7684\u65e0\u72b6\u6001\u8bbe\u8ba1\u662f\u4e00\u79cd\u523b\u610f\u7684\u53d6\u820d&#xff0c;\u800c\u975e\u7f3a\u9677\u3002\u670d\u52a1\u5668\u4e0d\u4fdd\u5b58\u5ba2\u6237\u7aef\u72b6\u6001&#xff0c;\u610f\u5473\u7740\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u662f\u81ea\u5305\u542b\u7684\u2014\u2014\u670d\u52a1\u5668\u4e0d\u9700\u8981\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u5206\u914d\u5185\u5b58\u6765\u8bb0\u4f4f&#034;\u4e4b\u524d\u53d1\u751f\u4e86\u4ec0\u4e48&#034;\u3002\u8fd9\u4f7f\u5f97\u4e00\u53f0 Web \u670d\u52a1\u5668\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u6570\u4e07\u8fde\u63a5\u800c\u4e0d\u4f1a\u5185\u5b58\u8017\u5c3d\u3002\u72b6\u6001\u7ba1\u7406\u88ab&#034;\u5916\u5305&#034;\u7ed9\u4e86\u4e0a\u5c42\u673a\u5236&#xff1a;Cookie&#xff08;\u5ba2\u6237\u7aef\u5b58\u50a8\u4f1a\u8bdd ID&#xff09;\u3001\u6570\u636e\u5e93&#xff08;\u670d\u52a1\u5668\u6301\u4e45\u5316\u72b6\u6001&#xff09;\u3001Token&#xff08;JWT \u7b49\u81ea\u5305\u542b\u8ba4\u8bc1\u51ed\u8bc1&#xff09;\u3002\u8fd9\u79cd\u5206\u5c42\u601d\u60f3\u8d2f\u7a7f\u4e86\u6574\u4e2a\u4e92\u8054\u7f51\u67b6\u6784\u2014\u2014\u4e0b\u5c42\u63d0\u4f9b\u7b80\u6d01\u53ef\u9760\u7684\u4f20\u8f93&#xff0c;\u4e0a\u5c42\u6309\u9700\u6dfb\u52a0\u529f\u80fd\u3002<\/p>\n<h4>1.1 \u8ba4\u8bc6 URL<\/h4>\n<p>\u5e73\u65f6\u8bf4\u7684&#034;\u7f51\u5740&#034;\u5c31\u662f URL&#xff08;Uniform Resource Locator&#xff09;\u3002\u4ee5 http:\/\/www.example.com:8080\/index.html?name&#061;zhangsan#chapter2 \u4e3a\u4f8b&#xff1a;<\/p>\n<p>http:\/\/www.example.com:8080\/index.html?name&#061;zhangsan#chapter2<br \/>\n\u2514\u252c\u2518  \u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u2514\u252c\u2518\u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2518\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u2514\u2500\u2500\u2500\u252c\u2500\u2500\u2518<br \/>\n \u534f\u8bae    \u57df\u540d\/IP    \u7aef\u53e3   \u8def\u5f84     \u67e5\u8be2\u5b57\u7b26\u4e32(query)  \u7247\u6bb5\u6807\u8bc6<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183607-6a63b0970c2e0.png\" alt=\"QQ20260609-211549\" \/><\/p>\n<table>\n<tr>\u7ec4\u6210\u90e8\u5206\u793a\u4f8b\u8bf4\u660e\u662f\u5426\u53d1\u7ed9\u670d\u52a1\u5668<\/tr>\n<tbody>\n<tr>\n<td>\u534f\u8bae<\/td>\n<td>http:\/\/<\/td>\n<td>\u4e5f\u53ef\u662f https:\/\/\u3002\u672c\u8d28\u4e0a\u53ea\u662f\u544a\u8bc9\u6d4f\u89c8\u5668\u7528\u54ea\u4e2a\u7aef\u53e3\u548c\u662f\u5426\u52a0\u5bc6<\/td>\n<td align=\"center\">\u274c<\/td>\n<\/tr>\n<tr>\n<td>\u57df\u540d\/IP<\/td>\n<td>www.example.com<\/td>\n<td>\u901a\u8fc7 DNS \u89e3\u6790\u83b7\u5f97\u670d\u52a1\u5668\u7684 IP \u5730\u5740<\/td>\n<td align=\"center\">\u274c&#xff08;IP \u5728 TCP \u8fde\u63a5\u65f6\u7528&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7aef\u53e3<\/td>\n<td>:8080<\/td>\n<td>\u7701\u7565\u65f6\u9ed8\u8ba4 80&#xff08;HTTP&#xff09;\u6216 443&#xff08;HTTPS&#xff09;<\/td>\n<td align=\"center\">\u274c&#xff08;TCP \u8fde\u63a5\u65f6\u7528&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8def\u5f84<\/td>\n<td>\/index.html<\/td>\n<td>\u670d\u52a1\u5668\u4e0a\u7684\u8d44\u6e90\u8def\u5f84\u3002\u8fd9\u662f Web \u670d\u52a1\u5668&#034;\u8def\u7531&#034;\u7684\u6838\u5fc3<\/td>\n<td align=\"center\">\u2705<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u8be2\u5b57\u7b26\u4e32<\/td>\n<td>?name&#061;zhangsan<\/td>\n<td>\u4f20\u7ed9\u670d\u52a1\u5668\u7684\u53c2\u6570&#xff0c;\u683c\u5f0f\u4e3a key&#061;value&amp;key&#061;value<\/td>\n<td align=\"center\">\u2705<\/td>\n<\/tr>\n<tr>\n<td>\u7247\u6bb5\u6807\u8bc6<\/td>\n<td>#chapter2<\/td>\n<td>\u9875\u9762\u5185\u90e8\u951a\u70b9\u5b9a\u4f4d<\/td>\n<td align=\"center\">\u274c \u4e0d\u53d1\u9001<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e3a\u4ec0\u4e48 fragments \u4e0d\u53d1\u7ed9\u670d\u52a1\u5668&#xff1f;\u56e0\u4e3a\u5b83\u7684\u4f5c\u7528\u662f\u9875\u9762\u5185\u90e8\u7684\u5bfc\u822a\u2014\u2014\u6d4f\u89c8\u5668\u62ff\u5230\u5b8c\u6574\u7684 HTML \u540e&#xff0c;\u81ea\u5df1\u6eda\u52a8\u5230 id&#061;&#034;chapter2&#034; \u7684\u4f4d\u7f6e\u3002\u8fd9\u5bf9\u4e8e\u7eaf\u9759\u6001\u9875\u9762\u5b8c\u5168\u5728\u5ba2\u6237\u7aef\u5b8c\u6210&#xff0c;\u4e0d\u9700\u8981\u670d\u52a1\u5668\u53c2\u4e0e\u3002<\/p>\n<p>URL \u7684\u8bbe\u8ba1\u770b\u4f3c\u7b80\u5355&#xff0c;\u80cc\u540e\u5374\u5305\u542b\u4e86\u7f51\u7edc\u5de5\u7a0b\u7684\u51e0\u4e2a\u6838\u5fc3\u6d1e\u5bdf\u3002\u6700\u503c\u5f97\u5173\u6ce8\u7684\u662f\u534f\u8bae\u4e0e\u8d44\u6e90\u7684\u5206\u79bb&#xff1a;URL \u7684\u524d\u534a\u90e8\u5206&#xff08;\u534f\u8bae\u3001\u57df\u540d\u3001\u7aef\u53e3&#xff09;\u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u600e\u4e48\u627e\u5230\u670d\u52a1\u5668&#034;&#xff0c;\u540e\u534a\u90e8\u5206&#xff08;\u8def\u5f84\u3001\u67e5\u8be2\u5b57\u7b26\u4e32&#xff09;\u544a\u8bc9\u670d\u52a1\u5668&#034;\u4f60\u8981\u4ec0\u4e48\u8d44\u6e90&#034;\u3002\u8fd9\u79cd\u5206\u79bb\u8ba9\u540c\u4e00\u53f0\u670d\u52a1\u5668\u53ef\u4ee5\u540c\u65f6\u670d\u52a1\u591a\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684 Web \u5e94\u7528&#xff08;\u901a\u8fc7\u4e0d\u540c\u7684\u8def\u5f84\u524d\u7f00&#xff09;&#xff0c;\u4e5f\u4e3a\u540e\u6765\u7684\u53cd\u5411\u4ee3\u7406\u548c API \u7f51\u5173\u5960\u5b9a\u4e86\u57fa\u7840\u2014\u2014Nginx \u770b\u5230 \/api\/ \u5f00\u5934\u7684\u8def\u5f84\u8f6c\u53d1\u7ed9\u540e\u7aef\u670d\u52a1&#xff0c;\u770b\u5230 \/static\/ \u76f4\u63a5\u4ece\u78c1\u76d8\u8fd4\u56de\u6587\u4ef6&#xff0c;\u770b\u5230 \/ \u8fd4\u56de\u524d\u7aef SPA \u9875\u9762\u3002\u6240\u6709\u8fd9\u4e00\u5207\u90fd\u57fa\u4e8e\u5bf9 URL \u8def\u5f84\u7684\u89e3\u6790&#xff0c;\u4e00\u884c\u4ee3\u7801\u90fd\u4e0d\u7528\u6539\u540e\u7aef\u2014\u2014\u8fd9\u6b63\u662f&#034;\u5173\u6ce8\u70b9\u5206\u79bb&#034;\u5728\u534f\u8bae\u5c42\u7684\u4f53\u73b0\u3002<\/p>\n<h4>1.2 urlencode \u4e0e urldecode<\/h4>\n<p>URL \u4e2d \/\u3001?\u3001:\u3001&amp;\u3001&#061; \u7b49\u5b57\u7b26\u6709\u7279\u6b8a\u542b\u4e49\u3002\u5982\u679c\u53c2\u6570\u672c\u8eab\u5305\u542b\u8fd9\u4e9b\u5b57\u7b26&#xff08;\u5982\u641c\u7d22 C&#043;&#043; \u4e2d\u7684 &#043;&#xff09;&#xff0c;\u5fc5\u987b\u8f6c\u4e49\u3002\u8f6c\u4e49\u89c4\u5219&#xff1a;\u5c06\u5b57\u7b26\u7684\u6bcf\u4e2a\u5b57\u8282\u7528 16 \u8fdb\u5236\u8868\u793a&#xff0c;\u524d\u9762\u52a0 %&#xff1a;<\/p>\n<table>\n<tr>\u5b57\u7b26\u8f6c\u4e49\u540e\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>&#043;<\/td>\n<td>%2B<\/td>\n<td>&#043; \u5728 URL \u4e2d\u5e38\u88ab\u89e3\u6790\u4e3a\u7a7a\u683c&#xff08;\u5386\u53f2\u539f\u56e0&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a\u683c<\/td>\n<td>%20&#xff08;\u6216 &#043;&#xff09;<\/td>\n<td>%20 \u662f\u6807\u51c6\u5199\u6cd5&#xff0c;&#043; \u662f\u8868\u5355\u63d0\u4ea4\u7684\u9057\u7559\u5199\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>\/<\/td>\n<td>%2F<\/td>\n<td>\u4e0d\u52a0\u8f6c\u4e49\u4f1a\u88ab\u8bef\u89e3\u4e3a\u8def\u5f84\u5206\u9694\u7b26<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>%3F<\/td>\n<td>\u4e0d\u52a0\u8f6c\u4e49\u4f1a\u88ab\u8bef\u89e3\u4e3a\u67e5\u8be2\u5b57\u7b26\u4e32\u8d77\u70b9<\/td>\n<\/tr>\n<tr>\n<td>&amp;<\/td>\n<td>%26<\/td>\n<td>\u4e0d\u52a0\u8f6c\u4e49\u4f1a\u88ab\u8bef\u89e3\u4e3a\u53c2\u6570\u5206\u9694\u7b26<\/td>\n<\/tr>\n<tr>\n<td>&#061;<\/td>\n<td>%3D<\/td>\n<td>\u4e0d\u52a0\u8f6c\u4e49\u4f1a\u88ab\u8bef\u89e3\u4e3a\u952e\u503c\u5206\u9694\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d (UTF-8: E4 B8 AD)<\/td>\n<td>%E4%B8%AD<\/td>\n<td>\u4e2d\u6587\u548c\u5176\u4ed6\u975e ASCII \u5b57\u7b26\u5168\u90e8\u9700\u8981\u8f6c\u4e49<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"token comment\">\/\/ urldecode \u7684\u7b80\u5355\u5b9e\u73b0<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;cctype&gt;<\/span><\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">UrlDecode<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>src<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>string ret<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span>size_t i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> src<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token char\">&#039;%&#039;<\/span> <span class=\"token operator\">&amp;&amp;<\/span> i <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">2<\/span> <span class=\"token operator\">&lt;<\/span> src<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token function\">isxdigit<\/span><span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token function\">isxdigit<\/span><span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ %XY \u2192 \u628a XY \u5f53\u4f5c 16 \u8fdb\u5236\u89e3\u6790<\/span><br \/>\n            <span class=\"token keyword\">char<\/span> hex<span class=\"token punctuation\">[<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span>src<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> src<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            ret <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token generic-function\"><span class=\"token function\">static_cast<\/span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">strtol<\/span><span class=\"token punctuation\">(<\/span>hex<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">16<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            i <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token char\">&#039;&#043;&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            ret <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token char\">&#039; &#039;<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8868\u5355\u63d0\u4ea4\u4e2d &#043; \u4ee3\u8868\u7a7a\u683c<\/span><br \/>\n        <span class=\"token keyword\">else<\/span><br \/>\n            ret <span class=\"token operator\">&#043;&#061;<\/span> src<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> ret<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u4e8c\u3001HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u683c\u5f0f<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183608-6a63b0984b69a.png\" alt=\"QQ20260523-195931\" \/><\/p>\n<p>HTTP \u534f\u8bae\u7684\u6838\u5fc3\u662f\u4e09\u90e8\u5206&#xff1a;\u9996\u884c&#xff08;\u8bf7\u6c42\u884c\/\u72b6\u6001\u884c&#xff09;&#043; Header &#043; Body\u3002\u9996\u884c\u548c Header \u90fd\u662f\u7eaf\u6587\u672c\u3001\u4ee5 \\\\r\\\\n \u7ed3\u5c3e&#xff0c;Header \u548c Body \u4e4b\u95f4\u7528\u4e00\u4e2a\u7a7a\u884c&#xff08;\u5373 \\\\r\\\\n\\\\r\\\\n&#xff09;\u5206\u9694\u3002<\/p>\n<h4>2.1 \u8bf7\u6c42\u683c\u5f0f<\/h4>\n<p>GET \/index.html HTTP\/1.1\\\\r\\\\n          \u2190 \u9996\u884c&#xff08;\u8bf7\u6c42\u884c&#xff09;<br \/>\nHost: www.example.com\\\\r\\\\n             \u2190 Header<br \/>\nUser-Agent: Mozilla\/5.0\\\\r\\\\n<br \/>\nAccept: text\/html\\\\r\\\\n<br \/>\nContent-Length: 27\\\\r\\\\n<br \/>\n\\\\r\\\\n                                   \u2190 \u7a7a\u884c&#xff08;Header \u7ed3\u675f\u6807\u5fd7&#xff09;<br \/>\nusername&#061;zhangsan&amp;password&#061;123456     \u2190 Body&#xff08;\u53ef\u9009&#xff09;<\/p>\n<table>\n<tr>\u90e8\u5206\u683c\u5f0f\u8bf4\u660e\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u9996\u884c<\/td>\n<td>[\u65b9\u6cd5] [URL\u8def\u5f84] [\u7248\u672c]\\\\r\\\\n<\/td>\n<td>\u7a7a\u683c\u5206\u9694&#xff0c;\u7248\u672c\u901a\u5e38\u662f HTTP\/1.1 \u6216 HTTP\/1.0<\/td>\n<td>GET \/api\/user HTTP\/1.1<\/td>\n<\/tr>\n<tr>\n<td>Header<\/td>\n<td>\u952e: \u503c\\\\r\\\\n<\/td>\n<td>\u82e5\u5e72\u884c\u952e\u503c\u5bf9&#xff0c;\u5192\u53f7\u540e\u5fc5\u987b\u6709\u4e00\u4e2a\u7a7a\u683c\u3002\u9047\u5230\u7a7a\u884c\u7ed3\u675f<\/td>\n<td>Content-Type: text\/html<\/td>\n<\/tr>\n<tr>\n<td>Body<\/td>\n<td>\u4efb\u610f\u6570\u636e<\/td>\n<td>Body \u957f\u5ea6\u7531 Content-Length \u6307\u5b9a&#xff0c;\u6ca1\u6709 Body \u65f6\u6b64\u9879\u4e3a\u7a7a<\/td>\n<td>{&#034;name&#034;:&#034;zhangsan&#034;}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 \u54cd\u5e94\u683c\u5f0f<\/h4>\n<p>HTTP\/1.1 200 OK\\\\r\\\\n                    \u2190 \u9996\u884c&#xff08;\u72b6\u6001\u884c&#xff09;<br \/>\nContent-Type: text\/html\\\\r\\\\n           \u2190 Header<br \/>\nContent-Length: 20\\\\r\\\\n<br \/>\nConnection: keep-alive\\\\r\\\\n<br \/>\n\\\\r\\\\n                                   \u2190 \u7a7a\u884c<br \/>\n&lt;h1&gt;hello world&lt;\/h1&gt;                  \u2190 Body<\/p>\n<table>\n<tr>\u90e8\u5206\u683c\u5f0f\u8bf4\u660e\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u9996\u884c<\/td>\n<td>[\u7248\u672c] [\u72b6\u6001\u7801] [\u72b6\u6001\u63cf\u8ff0]\\\\r\\\\n<\/td>\n<td>\u72b6\u6001\u63cf\u8ff0\u662f\u7ed9\u4eba\u770b\u7684&#xff0c;\u7a0b\u5e8f\u53ea\u770b\u72b6\u6001\u7801<\/td>\n<td>HTTP\/1.1 404 Not Found<\/td>\n<\/tr>\n<tr>\n<td>Header<\/td>\n<td>\u952e: \u503c\\\\r\\\\n<\/td>\n<td>\u4e0e\u8bf7\u6c42 Header \u683c\u5f0f\u5b8c\u5168\u4e00\u81f4<\/td>\n<td>Content-Type: text\/html<\/td>\n<\/tr>\n<tr>\n<td>Body<\/td>\n<td>\u4efb\u610f\u6570\u636e<\/td>\n<td>\u5982 HTML\u3001JSON\u3001\u56fe\u7247\u7684\u4e8c\u8fdb\u5236\u6570\u636e<\/td>\n<td>&lt;html&gt;&#8230;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8bf7\u6c42\u548c\u54cd\u5e94\u7ed3\u6784\u9ad8\u5ea6\u5bf9\u79f0\u3002\u638c\u63e1\u8fd9\u4e2a\u6a21\u677f&#xff0c;\u610f\u5473\u7740\u4f60\u80fd\u624b\u5de5\u6784\u9020\u4efb\u4f55 HTTP \u62a5\u6587\u2014\u2014\u65e0\u8bba\u662f\u7528 C&#043;&#043; \u5199 Web \u670d\u52a1\u5668&#xff0c;\u8fd8\u662f\u7528 Python socket \u6d4b\u8bd5 API&#xff0c;\u8fd8\u662f\u5728\u7ec8\u7aef\u7528 nc&#xff08;netcat&#xff09;\u53d1\u9001\u88f8 HTTP \u8bf7\u6c42\u8c03\u8bd5\u540e\u7aef\u3002<\/p>\n<p>HTTP \u534f\u8bae\u683c\u5f0f\u4e2d\u6709\u4e00\u4e2a\u6781\u5176\u7cbe\u5999\u4f46\u5bb9\u6613\u88ab\u5ffd\u89c6\u7684\u8bbe\u8ba1&#xff1a;\u9996\u884c\u548c Header \u7528 \\\\r\\\\n \u7ed3\u5c3e&#xff0c;Header \u548c Body \u4e4b\u95f4\u7528\u7a7a\u884c \\\\r\\\\n\\\\r\\\\n \u5206\u9694\u3002 \u8fd9\u610f\u5473\u7740 HTTP \u62a5\u6587\u7684\u89e3\u6790\u53ea\u9700\u8981\u4e00\u4e2a\u7b80\u5355\u7684\u5b57\u7b26\u4e32\u5339\u914d\u2014\u2014\u627e\u5230\u7b2c\u4e00\u4e2a \\\\r\\\\n \u5c31\u662f\u9996\u884c&#xff0c;\u7ee7\u7eed\u627e\u76f4\u5230\u9047\u5230\u8fde\u7eed\u4e24\u4e2a \\\\r\\\\n&#xff08;\u5373\u4e00\u4e2a\u7a7a\u884c&#xff09;&#xff0c;\u4e4b\u524d\u7684\u6240\u6709\u884c\u90fd\u662f Header&#xff0c;\u4e4b\u540e\u7684\u6240\u6709\u5b57\u8282\u90fd\u662f Body\u3002\u4e0d\u9700\u8981\u590d\u6742\u7684\u4e8c\u8fdb\u5236\u89e3\u6790\u5668&#xff0c;\u4e0d\u9700\u8981\u5b9a\u4e49\u957f\u5ea6\u524d\u7f00&#xff08;Body \u7684\u957f\u5ea6\u7528 Content-Length \u8fd9\u4e2a\u666e\u901a Header \u5b57\u6bb5\u6307\u5b9a&#xff09;&#xff0c;\u751a\u81f3\u4e0d\u9700\u8981\u4e13\u95e8\u7684\u5e93\u2014\u2014\u4e00\u4e2a\u4f1a\u5199 C \u8bed\u8a00\u5b57\u7b26\u4e32\u5904\u7406\u7684\u5927\u5b66\u751f\u5c31\u80fd\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684 HTTP \u89e3\u6790\u5668\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u51b3\u7b56\u662f HTTP \u80fd\u8fc5\u901f\u666e\u53ca\u7684\u5173\u952e\u56e0\u7d20&#xff1a;\u534f\u8bae\u8d8a\u5bb9\u6613\u5b9e\u73b0&#xff0c;\u91c7\u7528\u5b83\u7684\u5f00\u53d1\u8005\u5c31\u8d8a\u591a\u3002<\/p>\n<p>\u4e0e HTTP \u76f8\u53cd\u7684\u53cd\u9762\u6559\u6750\u662f\u65e9\u671f\u7684 HTTP\/2 \u4e4b\u524d\u7684\u5f88\u591a\u4e8c\u8fdb\u5236\u534f\u8bae\u2014\u2014\u5b83\u4eec\u7528\u81ea\u5b9a\u4e49\u7684\u5e27\u683c\u5f0f\u3001\u590d\u6742\u7684\u4f4d\u57df\u7f16\u7801&#xff0c;\u5b9e\u73b0\u8d77\u6765\u9700\u8981\u4e13\u95e8\u7684\u72b6\u6001\u673a\u548c\u5f88\u591a\u9875\u7684 RFC\u3002\u8fd9\u7c7b\u534f\u8bae\u5728\u5b66\u672f\u754c\u5f88\u4f18\u96c5&#xff0c;\u5728\u5de5\u4e1a\u754c\u5374\u8f93\u7ed9\u4e86 HTTP \u7684\u7eaf\u6587\u672c\u4e3b\u4e49\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48&#034;\u4eba\u7c7b\u53ef\u8bfb&#034;\u5728\u534f\u8bae\u8bbe\u8ba1\u4e2d\u4e0d\u662f\u9526\u4e0a\u6dfb\u82b1\u2014\u2014\u5f53\u5f00\u53d1\u8005\u80fd\u5728\u7ec8\u7aef\u76f4\u63a5\u770b\u5230 GET \/ HTTP\/1.1 \u5e76\u7406\u89e3\u5b83\u7684\u542b\u4e49\u65f6&#xff0c;\u8c03\u8bd5\u65f6\u95f4\u4ece\u5929\u7ea7\u522b\u964d\u5230\u4e86\u5206\u949f\u7ea7\u522b\u3002<\/p>\n<h4>2.3 \u624b\u5de5\u9a8c\u8bc1&#xff1a;\u7528 netcat \u53d1\u9001 HTTP \u8bf7\u6c42<\/h4>\n<p><span class=\"token comment\"># \u7ec8\u7aef1&#xff1a;\u542f\u52a8\u4e00\u4e2a TCP \u76d1\u542c<\/span><br \/>\n$ <span class=\"token function\">nc<\/span> <span class=\"token parameter variable\">-l<\/span> <span class=\"token number\">9999<\/span><\/p>\n<p><span class=\"token comment\"># \u7ec8\u7aef2&#xff1a;\u7528\u6d4f\u89c8\u5668\u8bbf\u95ee http:\/\/127.0.0.1:9999<\/span><br \/>\n<span class=\"token comment\"># \u7ec8\u7aef1 \u4f1a\u6253\u5370\u6d4f\u89c8\u5668\u53d1\u6765\u7684\u5b8c\u6574 HTTP \u8bf7\u6c42&#xff1a;<\/span><\/p>\n<p>GET \/ HTTP\/1.1<br \/>\nHost: <span class=\"token number\">127.0<\/span>.0.1:9999<br \/>\nConnection: keep-alive<br \/>\nUpgrade-Insecure-Requests: <span class=\"token number\">1<\/span><br \/>\nUser-Agent: Mozilla\/5.0 <span class=\"token punctuation\">(<\/span>Windows NT <span class=\"token number\">10.0<\/span><span class=\"token punctuation\">;<\/span> Win64<span class=\"token punctuation\">;<\/span> x64<span class=\"token punctuation\">)<\/span> AppleWebKit\/537.36<br \/>\nAccept: text\/html,application\/xhtml&#043;xml,<span class=\"token punctuation\">..<\/span>.<br \/>\nAccept-Encoding: gzip, deflate<br \/>\nAccept-Language: zh-CN,zh<span class=\"token punctuation\">;<\/span><span class=\"token assign-left variable\">q<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">0.9<\/span><\/p>\n<p>\u8fd9\u4e2a\u5b9e\u9a8c\u975e\u5e38\u76f4\u89c2&#xff1a;\u4f60\u770b\u5230\u7684\u6bcf\u4e00\u884c\u90fd\u662f\u6d4f\u89c8\u5668\u81ea\u52a8\u751f\u6210\u7684 HTTP Header\u3002\u7406\u89e3\u4e86\u8fd9\u4e9b Header \u7684\u542b\u4e49&#xff0c;\u4f60\u5c31\u7406\u89e3\u4e86\u6d4f\u89c8\u5668\u7684\u5fc3\u601d\u3002<\/p>\n<h3>\u4e09\u3001HTTP \u65b9\u6cd5<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183609-6a63b0992b26a.png\" alt=\"QQ20260523-200152\" \/><\/p>\n<p>HTTP \u65b9\u6cd5\u5b9a\u4e49\u4e86\u5bf9\u8d44\u6e90\u7684\u64cd\u4f5c\u8bed\u4e49\u3002\u6700\u5e38\u7528\u7684\u4e24\u4e2a\u662f GET \u548c POST\u2014\u2014\u5b83\u4eec\u4fe9\u5360\u4e86 HTTP \u8bf7\u6c42\u7684 95% \u4ee5\u4e0a\u3002<\/p>\n<table>\n<tr>\u65b9\u6cd5\u7528\u9014Body\u5e42\u7b49\u5178\u578b\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>GET<\/td>\n<td>\u8bf7\u6c42\u6307\u5b9a\u8d44\u6e90<\/td>\n<td>\u901a\u5e38\u65e0<\/td>\n<td>\u2705<\/td>\n<td>\u8bbf\u95ee\u7f51\u9875\u3001\u641c\u7d22\u3001API \u67e5\u8be2(\u201c\u7ed9\u6211\u7528\u6237id&#061;5\u7684\u6570\u636e\u201d)<\/td>\n<\/tr>\n<tr>\n<td>POST<\/td>\n<td>\u63d0\u4ea4\u6570\u636e\u7ed9\u670d\u52a1\u5668<\/td>\n<td>\u6709<\/td>\n<td>\u274c<\/td>\n<td>\u8868\u5355\u63d0\u4ea4\u3001\u767b\u5f55\u3001\u6587\u4ef6\u4e0a\u4f20\u3001\u65b0\u5efa\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>HEAD<\/td>\n<td>\u4e0e GET \u76f8\u540c\u4f46\u53ea\u8fd4\u56de Header<\/td>\n<td>\u65e0<\/td>\n<td>\u2705<\/td>\n<td>\u68c0\u67e5\u8d44\u6e90\u662f\u5426\u5b58\u5728\u6216\u662f\u5426\u88ab\u4fee\u6539<\/td>\n<\/tr>\n<tr>\n<td>PUT<\/td>\n<td>\u4e0a\u4f20\u6587\u4ef6\u5230\u6307\u5b9a\u4f4d\u7f6e<\/td>\n<td>\u6709<\/td>\n<td>\u2705<\/td>\n<td>RESTful API \u66f4\u65b0\u8d44\u6e90&#xff08;\u201c\u628aid&#061;5\u7684\u7528\u6237\u4fe1\u606f\u6539\u6210\u8fd9\u4e2a\u201d&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>DELETE<\/td>\n<td>\u5220\u9664\u6307\u5b9a\u8d44\u6e90<\/td>\n<td>\u901a\u5e38\u65e0<\/td>\n<td>\u2705<\/td>\n<td>RESTful API \u5220\u9664\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>OPTIONS<\/td>\n<td>\u67e5\u8be2\u670d\u52a1\u5668\u5bf9\u6b64 URL \u652f\u6301\u7684\u65b9\u6cd5<\/td>\n<td>\u65e0<\/td>\n<td>\u2705<\/td>\n<td>CORS \u9884\u68c0\u8bf7\u6c42&#xff08;\u8de8\u57dfAJAX\u7684\u524d\u7f6e\u68c0\u67e5&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.1 GET \u4e0e POST \u7684\u6838\u5fc3\u533a\u522b<\/h4>\n<table>\n<tr>\u5bf9\u6bd4\u7ef4\u5ea6GETPOST<\/tr>\n<tbody>\n<tr>\n<td>\u53c2\u6570\u4f4d\u7f6e<\/td>\n<td>URL \u7684\u67e5\u8be2\u5b57\u7b26\u4e32\u4e2d&#xff08;?key&#061;value&#xff09;<\/td>\n<td>Body \u4e2d<\/td>\n<\/tr>\n<tr>\n<td>\u957f\u5ea6\u9650\u5236<\/td>\n<td>URL \u957f\u5ea6\u6709\u9650&#xff08;\u6d4f\u89c8\u5668\/\u670d\u52a1\u5668\u9650\u5236&#xff0c;\u7ea6 2KB~8KB&#xff09;<\/td>\n<td>\u65e0\u660e\u786e\u9650\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u5b89\u5168\u6027<\/td>\n<td>\u53c2\u6570\u66b4\u9732\u5728 URL \u4e2d&#xff0c;\u4e0d\u9002\u5408\u4f20\u5bc6\u7801<\/td>\n<td>\u53c2\u6570\u5728 Body \u4e2d&#xff0c;\u76f8\u5bf9\u9690\u853d&#xff08;\u4f46\u4ecd\u9700 HTTPS&#xff01;&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7f13\u5b58<\/td>\n<td>\u6d4f\u89c8\u5668\u53ef\u4ee5\u7f13\u5b58 GET \u7ed3\u679c<\/td>\n<td>\u901a\u5e38\u4e0d\u7f13\u5b58<\/td>\n<\/tr>\n<tr>\n<td>\u4e66\u7b7e<\/td>\n<td>\u53ef\u4ee5\u4e66\u7b7e\u4fdd\u5b58&#xff08;\u53c2\u6570\u5728 URL \u4e2d&#xff09;<\/td>\n<td>\u4e0d\u80fd\u4e66\u7b7e&#xff08;\u53c2\u6570\u5728 Body \u4e2d&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5e42\u7b49<\/td>\n<td>\u591a\u6b21\u8bf7\u6c42\u7ed3\u679c\u76f8\u540c<\/td>\n<td>\u591a\u6b21\u8bf7\u6c42\u53ef\u80fd\u521b\u5efa\u591a\u6761\u8bb0\u5f55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5173\u952e\u7406\u89e3&#xff1a;POST \u7684&#034;\u5b89\u5168\u6027&#034;\u4ec5\u9650\u4e8e URL \u4e0d\u53ef\u89c1\u2014\u2014\u5982\u679c\u4e0d\u7528 HTTPS&#xff0c;POST Body \u4e2d\u7684\u5bc6\u7801\u540c\u6837\u662f\u660e\u6587\u4f20\u8f93&#xff0c;\u4e2d\u95f4\u8def\u7531\u5668\u53ef\u4ee5\u5b8c\u6574\u770b\u5230\u3002HTTP \u5c42\u9762\u7684\u5b89\u5168 &#061; HTTPS&#xff0c;\u4e0d\u662f GET vs POST\u3002<\/p>\n<h4>3.2 \u8868\u5355\u63d0\u4ea4&#xff1a;GET \u8fd8\u662f POST<\/h4>\n<p>HTML &lt;form&gt; \u6807\u7b7e\u7684 method \u5c5e\u6027\u51b3\u5b9a\u4e86\u63d0\u4ea4\u65b9\u5f0f&#xff1a;<\/p>\n<p><span class=\"token comment\">&lt;!&#8211; GET \u8868\u5355 \u2192 \u53c2\u6570\u62fc\u63a5\u5728 URL \u4e2d &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>form<\/span> <span class=\"token attr-name\">action<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>\/search<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">method<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>GET<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>q<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>text<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input<\/span> <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>submit<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>form<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token comment\">&lt;!&#8211; \u63d0\u4ea4\u540e\u6d4f\u89c8\u5668 URL \u53d8\u4e3a: \/search?q&#061;\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9 &#8211;&gt;<\/span><\/p>\n<p><span class=\"token comment\">&lt;!&#8211; POST \u8868\u5355 \u2192 \u53c2\u6570\u653e\u5728 Body \u4e2d &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>form<\/span> <span class=\"token attr-name\">action<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>\/login<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">method<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>POST<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>username<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>text<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>password<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>password<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input<\/span> <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>submit<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>form<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token comment\">&lt;!&#8211; \u63d0\u4ea4\u540e URL \u4e0d\u53d8&#xff0c;\u7528\u6237\u540d\u548c\u5bc6\u7801\u5728 Body \u4e2d\u4f20\u8f93 &#8211;&gt;<\/span><\/p>\n<h3>\u56db\u3001HTTP \u72b6\u6001\u7801\u4e0e\u91cd\u5b9a\u5411<\/h3>\n<h4>4.1 \u72b6\u6001\u7801\u901f\u67e5<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183609-6a63b099d23e1.png\" alt=\"QQ20260609-211841\" \/><\/p>\n<p>\u72b6\u6001\u7801\u4e09\u4f4d\u6570\u5b57&#xff0c;\u7b2c\u4e00\u4f4d\u8868\u793a\u54cd\u5e94\u7c7b\u522b\u3002\u6807\u51c6\u72b6\u6001\u7801\u6709\u51e0\u5341\u4e2a&#xff0c;\u4f46\u65e5\u5e38\u5f00\u53d1\u63a5\u89e6\u7684\u4e3b\u8981\u662f\u8fd9\u51e0\u4e2a&#xff1a;<\/p>\n<table>\n<tr>\u7c7b\u522b\u8303\u56f4\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>1xx<\/td>\n<td>100~199<\/td>\n<td>\u4fe1\u606f\u6027\u72b6\u6001\u7801\u2014\u2014\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42&#xff0c;\u7ee7\u7eed\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>2xx<\/td>\n<td>200~299<\/td>\n<td>\u6210\u529f\u2014\u2014\u8bf7\u6c42\u88ab\u6b63\u5e38\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>3xx<\/td>\n<td>300~399<\/td>\n<td>\u91cd\u5b9a\u5411\u2014\u2014\u9700\u8981\u8fdb\u4e00\u6b65\u64cd\u4f5c<\/td>\n<\/tr>\n<tr>\n<td>4xx<\/td>\n<td>400~499<\/td>\n<td>\u5ba2\u6237\u7aef\u9519\u8bef\u2014\u2014\u8bf7\u6c42\u6709\u95ee\u9898<\/td>\n<\/tr>\n<tr>\n<td>5xx<\/td>\n<td>500~599<\/td>\n<td>\u670d\u52a1\u5668\u9519\u8bef\u2014\u2014\u670d\u52a1\u5668\u51fa\u4e86\u95ee\u9898<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u5e38\u7528\u7684\u72b6\u6001\u7801&#xff1a;<\/p>\n<table>\n<tr>\u72b6\u6001\u7801\u542b\u4e49\u4f55\u65f6\u51fa\u73b0\u4f60\u80fd\u505a\u4ec0\u4e48<\/tr>\n<tbody>\n<tr>\n<td>200<\/td>\n<td>OK<\/td>\n<td>\u8bf7\u6c42\u6210\u529f<\/td>\n<td>\u6b63\u5e38\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>201<\/td>\n<td>Created<\/td>\n<td>POST \u521b\u5efa\u8d44\u6e90\u6210\u529f<\/td>\n<td>\u8fd4\u56de\u65b0\u8d44\u6e90\u7684 URL<\/td>\n<\/tr>\n<tr>\n<td>204<\/td>\n<td>No Content<\/td>\n<td>\u5220\u9664\u6210\u529f&#xff0c;\u65e0\u8fd4\u56de\u5185\u5bb9<\/td>\n<td>\u544a\u8bc9\u5ba2\u6237\u7aef\u64cd\u4f5c\u5b8c\u6210\u5373\u53ef<\/td>\n<\/tr>\n<tr>\n<td>301<\/td>\n<td>Moved Permanently<\/td>\n<td>\u8d44\u6e90\u6c38\u4e45\u8fc1\u79fb<\/td>\n<td>\u6d4f\u89c8\u5668\u81ea\u52a8\u8df3\u8f6c\u5e76\u7f13\u5b58\u65b0\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td>302<\/td>\n<td>Found<\/td>\n<td>\u8d44\u6e90\u4e34\u65f6\u8fc1\u79fb<\/td>\n<td>\u6d4f\u89c8\u5668\u8df3\u8f6c\u4f46\u4e0d\u7f13\u5b58<\/td>\n<\/tr>\n<tr>\n<td>304<\/td>\n<td>Not Modified<\/td>\n<td>\u5ba2\u6237\u7aef\u7f13\u5b58\u7684\u8d44\u6e90\u672a\u8fc7\u671f<\/td>\n<td>\u6d4f\u89c8\u5668\u76f4\u63a5\u7528\u672c\u5730\u7f13\u5b58<\/td>\n<\/tr>\n<tr>\n<td>400<\/td>\n<td>Bad Request<\/td>\n<td>\u8bf7\u6c42\u683c\u5f0f\u9519\u8bef&#xff08;JSON \u683c\u5f0f\u975e\u6cd5\u7b49&#xff09;<\/td>\n<td>\u544a\u8bc9\u7528\u6237\u8f93\u5165\u6709\u95ee\u9898<\/td>\n<\/tr>\n<tr>\n<td>401<\/td>\n<td>Unauthorized<\/td>\n<td>\u672a\u767b\u5f55\u6216\u8ba4\u8bc1\u5931\u8d25<\/td>\n<td>\u8df3\u8f6c\u5230\u767b\u5f55\u9875<\/td>\n<\/tr>\n<tr>\n<td>403<\/td>\n<td>Forbidden<\/td>\n<td>\u5df2\u767b\u5f55\u4f46\u65e0\u6743\u8bbf\u95ee<\/td>\n<td>\u663e\u793a&#034;\u6ca1\u6709\u6743\u9650&#034;<\/td>\n<\/tr>\n<tr>\n<td>404<\/td>\n<td>Not Found<\/td>\n<td>\u8d44\u6e90\u4e0d\u5b58\u5728<\/td>\n<td>\u663e\u793a 404 \u9875\u9762<\/td>\n<\/tr>\n<tr>\n<td>500<\/td>\n<td>Internal Server Error<\/td>\n<td>\u670d\u52a1\u5668\u4ee3\u7801\u629b\u5f02\u5e38\u4e86<\/td>\n<td>\u68c0\u67e5\u670d\u52a1\u7aef\u65e5\u5fd7<\/td>\n<\/tr>\n<tr>\n<td>502<\/td>\n<td>Bad Gateway<\/td>\n<td>\u4ee3\u7406\/\u7f51\u5173\u4ece\u4e0a\u6e38\u6536\u5230\u65e0\u6548\u54cd\u5e94<\/td>\n<td>\u68c0\u67e5\u4e0a\u6e38\u670d\u52a1\u662f\u5426\u6b63\u5e38<\/td>\n<\/tr>\n<tr>\n<td>503<\/td>\n<td>Service Unavailable<\/td>\n<td>\u670d\u52a1\u5668\u8fc7\u8f7d\u6216\u7ef4\u62a4\u4e2d<\/td>\n<td>\u7a0d\u540e\u91cd\u8bd5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.2 \u91cd\u5b9a\u5411\u7684\u5e95\u5c42\u673a\u5236<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183611-6a63b09b1ba3c.png\" alt=\"QQ20260609-212043\" \/><\/p>\n<p>HTTP\/1.1 301 Moved Permanently\\\\r\\\\n<br \/>\nLocation: https:\/\/www.new-url.com\\\\r\\\\n<br \/>\n\\\\r\\\\n<\/p>\n<p>301&#xff08;\u6c38\u4e45&#xff09;vs 302&#xff08;\u4e34\u65f6&#xff09;\u7684\u6838\u5fc3\u5dee\u5f02\u5728\u6d4f\u89c8\u5668\u884c\u4e3a&#xff1a;<\/p>\n<table>\n<tr>\u7279\u6027301&#xff08;\u6c38\u4e45\u91cd\u5b9a\u5411&#xff09;302&#xff08;\u4e34\u65f6\u91cd\u5b9a\u5411&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u6d4f\u89c8\u5668\u7f13\u5b58<\/td>\n<td>\u7f13\u5b58\u91cd\u5b9a\u5411\u76ee\u6807\u2014\u2014\u4e0b\u6b21\u76f4\u63a5\u53bb\u65b0 URL<\/td>\n<td>\u4e0d\u7f13\u5b58\u2014\u2014\u6bcf\u6b21\u90fd\u95ee\u4e00\u6b21\u539f URL<\/td>\n<\/tr>\n<tr>\n<td>\u641c\u7d22\u5f15\u64ce<\/td>\n<td>\u66f4\u65b0\u7d22\u5f15&#xff0c;\u7528\u65b0 URL \u66ff\u6362\u65e7 URL<\/td>\n<td>\u4fdd\u6301\u65e7 URL&#xff0c;\u4f46\u5185\u5bb9\u4ece\u65b0 URL \u83b7\u53d6<\/td>\n<\/tr>\n<tr>\n<td>\u5178\u578b\u573a\u666f<\/td>\n<td>\u57df\u540d\u8fc1\u79fb\u3001HTTP\u2192HTTPS \u5347\u7ea7<\/td>\n<td>\u767b\u5f55\u6210\u529f\u540e\u8df3\u8f6c\u5230\u9996\u9875\u3001Post\/Redirect\/Get \u6a21\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7801\u5b9e\u73b0<\/td>\n<td>sprintf(response, &#034;HTTP\/1.1 301 Moved Permanently\\\\r\\\\nLocation: %s\\\\r\\\\n\\\\r\\\\n&#034;, new_url);<\/td>\n<td>sprintf(response, &#034;HTTP\/1.1 302 Found\\\\r\\\\nLocation: %s\\\\r\\\\n\\\\r\\\\n&#034;, new_url);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9762\u8bd5\u5e38\u89c1\u95ee\u9898&#xff1a;\u201cPost\/Redirect\/Get \u6a21\u5f0f\u662f\u4ec0\u4e48&#xff1f;\u201d\u2014\u2014\u7528\u6237 POST \u8868\u5355\u63d0\u4ea4\u540e&#xff0c;\u670d\u52a1\u5668\u8fd4\u56de 302 \u91cd\u5b9a\u5411\u5230\u4e00\u4e2a GET \u9875\u9762\u3002\u597d\u5904\u662f&#xff1a;\u7528\u6237\u6309 F5 \u5237\u65b0\u65f6&#xff0c;\u6d4f\u89c8\u5668\u91cd\u65b0 GET \u800c\u4e0d\u662f\u91cd\u65b0 POST&#xff08;\u91cd\u65b0 POST \u4f1a\u5bfc\u81f4\u91cd\u590d\u63d0\u4ea4&#xff0c;\u6bd4\u5982\u6263\u4e86\u4e24\u6b21\u6b3e&#xff09;\u3002<\/p>\n<p>\u72b6\u6001\u7801\u4f53\u7cfb\u8fd8\u6709\u4e00\u4e2a\u66f4\u6df1\u5c42\u7684\u8bbe\u8ba1\u667a\u6167&#xff1a;\u5b83\u628a&#034;\u6210\u529f&#034;\u548c&#034;\u5931\u8d25&#034;\u7684\u5b9a\u4e49\u6743\u4ea4\u7ed9\u4e86\u670d\u52a1\u5668&#xff0c;\u800c\u4e0d\u662f\u7f51\u7edc\u5c42\u3002 TCP \u5c42\u9762\u7684\u6210\u529f\u53ea\u610f\u5473\u7740&#034;\u5b57\u8282\u6d41\u5230\u8fbe\u4e86&#034;&#xff0c;\u4f46 HTTP \u5c42\u9762\u7684 200 \u624d\u4ee3\u8868&#034;\u8bf7\u6c42\u88ab\u6b63\u786e\u7406\u89e3\u3001\u8d44\u6e90\u5b58\u5728\u3001\u5904\u7406\u6210\u529f&#034;\u3002\u8fd9\u4e09\u5c42\u6821\u9a8c\u94fe\u2014\u2014TCP \u7684 ACK \u786e\u8ba4\u5b57\u8282\u5230\u8fbe\u3001HTTP \u7684 200 \u786e\u8ba4\u8bed\u4e49\u6b63\u786e\u3001\u5e94\u7528\u5c42\u7684\u4e1a\u52a1\u903b\u8f91\u7801\u786e\u8ba4\u4e1a\u52a1\u64cd\u4f5c\u6210\u529f\u2014\u2014\u5171\u540c\u6784\u6210\u4e86 Web \u670d\u52a1\u7684\u53ef\u9760\u6027\u57fa\u7840\u3002\u5f53\u4f60\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u770b\u5230\u5927\u91cf 5xx \u65f6&#xff0c;\u4f60\u77e5\u9053\u662f\u540e\u7aef\u51fa\u4e86\u95ee\u9898&#xff08;\u800c\u4e0d\u662f\u7f51\u7edc\u4e0d\u901a&#xff09;&#xff1b;\u770b\u5230\u5927\u91cf 4xx \u65f6&#xff0c;\u4f60\u77e5\u9053\u662f\u5ba2\u6237\u7aef\u53d1\u4e86\u9519\u8bef\u7684\u8bf7\u6c42\u3002\u8fd9\u79cd\u6545\u969c\u5b9a\u4f4d\u80fd\u529b\u6b63\u662f HTTP \u72b6\u6001\u7801\u4f53\u7cfb\u8d4b\u4e88\u7684\u3002<\/p>\n<h3>\u4e94\u3001HTTP \u5e38\u89c1 Header<\/h3>\n<p>Header \u662f HTTP \u534f\u8bae\u7684&#034;\u5143\u6570\u636e\u5c42&#034;\u2014\u2014\u5b83\u4e0d\u76f4\u63a5\u627f\u8f7d\u4e1a\u52a1\u6570\u636e&#xff0c;\u4f46\u51b3\u5b9a\u4e86\u6570\u636e\u5982\u4f55\u88ab\u4f20\u8f93\u3001\u7f13\u5b58\u548c\u89e3\u91ca\u3002<\/p>\n<h4>5.1 \u6838\u5fc3 Header \u4e00\u89c8<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183611-6a63b09bdee41.png\" alt=\"QQ20260609-212253\" \/><\/p>\n<table>\n<tr>Header\u65b9\u5411\u542b\u4e49\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>Host<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u76ee\u6807\u4e3b\u673a\u548c\u7aef\u53e3<\/td>\n<td>Host: www.example.com:8080<\/td>\n<\/tr>\n<tr>\n<td>Content-Type<\/td>\n<td>\u53cc\u5411<\/td>\n<td>Body \u7684 MIME \u7c7b\u578b<\/td>\n<td>text\/html;charset&#061;utf-8, application\/json<\/td>\n<\/tr>\n<tr>\n<td>Content-Length<\/td>\n<td>\u53cc\u5411<\/td>\n<td>Body \u7684\u5b57\u8282\u6570<\/td>\n<td>Content-Length: 1024<\/td>\n<\/tr>\n<tr>\n<td>User-Agent<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u5ba2\u6237\u7aef\u7684\u8f6f\u4ef6\u73af\u5883&#xff08;\u6d4f\u89c8\u5668\/\u64cd\u4f5c\u7cfb\u7edf&#xff09;<\/td>\n<td>Mozilla\/5.0 (Windows NT 10.0&#8230;)<\/td>\n<\/tr>\n<tr>\n<td>Accept<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u5ba2\u6237\u7aef\u80fd\u63a5\u6536\u7684\u54cd\u5e94\u7c7b\u578b<\/td>\n<td>Accept: text\/html,image\/webp<\/td>\n<\/tr>\n<tr>\n<td>Accept-Encoding<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u652f\u6301\u7684\u538b\u7f29\u683c\u5f0f<\/td>\n<td>Accept-Encoding: gzip, deflate, br<\/td>\n<\/tr>\n<tr>\n<td>Accept-Language<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u504f\u597d\u7684\u8bed\u8a00<\/td>\n<td>Accept-Language: zh-CN,zh;q&#061;0.9<\/td>\n<\/tr>\n<tr>\n<td>Referer<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u5f53\u524d\u8bf7\u6c42\u7684\u6765\u6e90\u9875\u9762 URL<\/td>\n<td>Referer: https:\/\/www.example.com\/prev<\/td>\n<\/tr>\n<tr>\n<td>Location<\/td>\n<td>\u54cd\u5e94<\/td>\n<td>\u914d\u5408 3xx \u72b6\u6001\u7801&#xff0c;\u6307\u5b9a\u91cd\u5b9a\u5411\u76ee\u6807<\/td>\n<td>Location: \/new-url<\/td>\n<\/tr>\n<tr>\n<td>Cookie<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u5ba2\u6237\u7aef\u5b58\u50a8\u7684\u4f1a\u8bdd\u4fe1\u606f<\/td>\n<td>Cookie: session_id&#061;abc123;theme&#061;dark<\/td>\n<\/tr>\n<tr>\n<td>Set-Cookie<\/td>\n<td>\u54cd\u5e94<\/td>\n<td>\u670d\u52a1\u5668\u8bbe\u7f6e Cookie<\/td>\n<td>Set-Cookie: session_id&#061;abc123; Path&#061;\/<\/td>\n<\/tr>\n<tr>\n<td>Connection<\/td>\n<td>\u53cc\u5411<\/td>\n<td>\u8fde\u63a5\u7ba1\u7406<\/td>\n<td>keep-alive&#xff08;\u4fdd\u6301&#xff09; \u6216 close&#xff08;\u5173\u95ed&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Cache-Control<\/td>\n<td>\u54cd\u5e94<\/td>\n<td>\u7f13\u5b58\u7b56\u7565<\/td>\n<td>Cache-Control: max-age&#061;3600<\/td>\n<\/tr>\n<tr>\n<td>Authorization<\/td>\n<td>\u8bf7\u6c42<\/td>\n<td>\u8ba4\u8bc1\u4fe1\u606f<\/td>\n<td>Authorization: Basic QWxhZGRpbjpvcGVu&#8230;<\/td>\n<\/tr>\n<tr>\n<td>Server<\/td>\n<td>\u54cd\u5e94<\/td>\n<td>\u670d\u52a1\u5668\u8f6f\u4ef6\u7c7b\u578b<\/td>\n<td>Server: nginx\/1.18.0<\/td>\n<\/tr>\n<tr>\n<td>Last-Modified<\/td>\n<td>\u54cd\u5e94<\/td>\n<td>\u8d44\u6e90\u6700\u540e\u4fee\u6539\u65f6\u95f4<\/td>\n<td>Last-Modified: Mon, 23 Jan 2023 13:27:56 GMT<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.2 \u6709\u8da3\u7684 User-Agent \u5386\u53f2<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183613-6a63b09d37859.png\" alt=\"QQ20260609-212522\" \/><\/p>\n<p>\u4f60\u53ef\u80fd\u6ce8\u610f\u5230 Chrome \u7684 User-Agent \u5199\u7740 Mozilla\/5.0 &#8230; AppleWebKit\/537.36 &#8230; Chrome\/91 &#8230; Safari\/537.36\u2014\u2014\u4e3a\u4ec0\u4e48\u4e00\u4e2a Chrome \u6d4f\u89c8\u5668\u8981\u540c\u65f6\u58f0\u79f0\u81ea\u5df1\u662f Mozilla\u3001AppleWebKit\u3001Safari&#xff1f;<\/p>\n<p>\u8fd9\u662f\u4e00\u90e8\u6d4f\u89c8\u5668\u6218\u4e89\u7684\u6d3b\u5316\u77f3&#xff1a;<\/p>\n<li>\u6700\u5f00\u59cb\u662f Netscape Navigator&#xff08;Mozilla&#xff09;<\/li>\n<li>IE \u4e3a\u4e86\u517c\u5bb9&#xff0c;\u58f0\u79f0\u81ea\u5df1\u662f \u201cMozilla\u201d<\/li>\n<li>Safari \u57fa\u4e8e KHTML \u6e32\u67d3\u5f15\u64ce&#xff08;AppleWebKit&#xff09;<\/li>\n<li>Chrome \u57fa\u4e8e WebKit \u5206\u652f&#xff08;Blink&#xff09;&#xff0c;\u4f46\u4e3a\u4e86\u4e0d\u89e6\u53d1&#034;Safari \u4e13\u7528&#034;\u7684\u670d\u52a1\u5668\u7aef\u5224\u65ad&#xff0c;\u4fdd\u7559\u4e86 AppleWebKit \u548c Safari \u7684\u6807\u8bb0<\/li>\n<p>\u8fd9\u4e2a&#034;\u8c0e\u62a5\u519b\u60c5&#034;\u7684 User-Agent \u4f20\u7edf\u4ece 1995 \u5e74\u5ef6\u7eed\u81f3\u4eca&#xff0c;\u56e0\u4e3a\u65e0\u6570\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u4f9d\u8d56\u5b83\u505a\u6d4f\u89c8\u5668\u517c\u5bb9\u5224\u65ad\u3002\u8fd9\u5c31\u662f\u6280\u672f\u503a\u5728\u534f\u8bae\u5c42\u7684\u4f53\u73b0\u2014\u2014\u4e3a\u4e86\u5411\u524d\u517c\u5bb9&#xff0c;\u65b0\u7248\u672c\u6c38\u8fdc\u5728\u5047\u88c5\u81ea\u5df1\u662f\u8001\u7248\u672c\u3002<\/p>\n<p>HTTP Header \u7684\u8bbe\u8ba1\u4e2d\u8fd8\u6709\u4e00\u4e2a\u503c\u5f97\u6df1\u601d\u7684\u5de5\u7a0b\u539f\u5219&#xff1a;\u6269\u5c55\u6027\u4f18\u5148\u4e8e\u5b8c\u5907\u6027\u3002 HTTP \u7684 Header \u6ca1\u6709\u9884\u5b9a\u4e49\u7684\u56fa\u5b9a\u5217\u8868\u2014\u2014\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49 Header&#xff08;\u5982 X-Request-ID \u7528\u4e8e\u5206\u5e03\u5f0f\u94fe\u8def\u8ffd\u8e2a&#xff09;\u3002\u670d\u52a1\u5668\u5bf9\u4e0d\u8ba4\u8bc6\u7684 Header \u9ed8\u8ba4\u5ffd\u7565&#xff0c;\u800c\u4e0d\u662f\u62a5\u9519\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u8ba9 HTTP \u53ef\u4ee5\u5728\u4e0d\u4fee\u6539\u534f\u8bae\u89c4\u8303\u7684\u60c5\u51b5\u4e0b\u88ab\u65e0\u9650\u6269\u5c55&#xff1a;\u7f13\u5b58\u63a7\u5236&#xff08;Cache-Control&#xff09;\u3001\u8de8\u57df\u8d44\u6e90\u5171\u4eab&#xff08;Access-Control-Allow-Origin&#xff09;\u3001\u5b89\u5168\u7b56\u7565&#xff08;Content-Security-Policy&#xff09;\u3001\u6027\u80fd\u4f18\u5316&#xff08;Link: &lt;style.css&gt;; rel&#061;preload&#xff09;\u2014\u2014\u90fd\u662f\u901a\u8fc7\u65b0\u7684 Header \u5b57\u6bb5\u9010\u6b65\u5f15\u5165\u7684&#xff0c;\u6ca1\u6709\u4e00\u4e2a\u9700\u8981\u4fee\u6539 HTTP \u534f\u8bae\u672c\u8eab\u3002\u76f8\u6bd4\u4e4b\u4e0b&#xff0c;\u5f88\u591a&#034;\u8bbe\u8ba1\u5f97\u66f4\u597d&#034;\u7684\u534f\u8bae\u56e0\u4e3a Header \u5217\u8868\u662f\u5c01\u95ed\u7684&#xff0c;\u6bcf\u6b21\u52a0\u65b0\u529f\u80fd\u90fd\u9700\u8981\u5347\u7ea7\u534f\u8bae\u7248\u672c\u53f7&#xff0c;\u5bfc\u81f4\u788e\u7247\u5316\u548c\u517c\u5bb9\u6027\u95ee\u9898\u3002\u5f00\u653e\u6269\u5c55\u3001\u5ffd\u7565\u672a\u77e5\u2014\u2014\u8fd9\u4e2a\u539f\u5219\u662f HTTP \u957f\u5bff\u7684\u79d8\u8bc0\u4e4b\u4e00\u3002<\/p>\n<h4>5.3 Connection \u5b57\u6bb5\u4e0e\u957f\u8fde\u63a5\u7684\u5de5\u7a0b\u610f\u4e49<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183614-6a63b09e35c53.png\" alt=\"QQ20260610-233202\" \/><\/p>\n<table>\n<tr>\u503c\u51fa\u73b0\u9ed8\u8ba4\u884c\u4e3a\u4f60\u8be5\u600e\u4e48\u505a<\/tr>\n<tbody>\n<tr>\n<td>Connection: keep-alive<\/td>\n<td>HTTP\/1.1<\/td>\n<td>\u9ed8\u8ba4\u4fdd\u6301\u8fde\u63a5&#xff0c;\u4e00\u4e2a TCP \u8fde\u63a5\u4e0a\u590d\u7528\u591a\u4e2a\u8bf7\u6c42<\/td>\n<td>\u274c \u4e0d\u7528\u624b\u52a8\u8bbe<\/td>\n<\/tr>\n<tr>\n<td>Connection: close<\/td>\n<td>HTTP\/1.0<\/td>\n<td>\u8bf7\u6c42\/\u54cd\u5e94\u5b8c\u6210\u540e\u7acb\u5373\u5173\u95ed TCP<\/td>\n<td>\u2705 \u5982\u679c\u4e0d\u60f3\u5904\u7406\u957f\u8fde\u63a5&#xff0c;\u76f4\u63a5\u8bbe\u8fd9\u4e2a<\/td>\n<\/tr>\n<tr>\n<td>\u4e0d\u52a0 Connection<\/td>\n<td>HTTP\/1.1<\/td>\n<td>\u7b49\u540c\u4e8e keep-alive<\/td>\n<td>\u2705 \u9ed8\u8ba4\u5c31\u662f\u957f\u8fde\u63a5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"token comment\">\/\/ HTTP\/1.0 \u7684\u663e\u5f0f\u957f\u8fde\u63a5<\/span><br \/>\nGET <span class=\"token operator\">\/<\/span>page1<span class=\"token punctuation\">.<\/span>html HTTP<span class=\"token operator\">\/<\/span><span class=\"token number\">1.0<\/span>\\\\r\\\\n<br \/>\nConnection<span class=\"token operator\">:<\/span> keep<span class=\"token operator\">&#8211;<\/span>alive\\\\r\\\\n<br \/>\n\\\\r\\\\n<\/p>\n<p><span class=\"token comment\">\/\/ HTTP\/1.1 \u7684\u9ed8\u8ba4\u957f\u8fde\u63a5\u2014\u2014\u60f3\u5173\u5c31\u663e\u5f0f\u8bbe close<\/span><br \/>\nGET <span class=\"token operator\">\/<\/span>page1<span class=\"token punctuation\">.<\/span>html HTTP<span class=\"token operator\">\/<\/span><span class=\"token number\">1.1<\/span>\\\\r\\\\n<br \/>\nHost<span class=\"token operator\">:<\/span> www<span class=\"token punctuation\">.<\/span>example<span class=\"token punctuation\">.<\/span>com\\\\r\\\\n<br \/>\nConnection<span class=\"token operator\">:<\/span> close\\\\r\\\\n   <span class=\"token comment\">\/\/ \u544a\u8bc9\u670d\u52a1\u5668&#xff1a;\u8fd9\u6b21\u8bf7\u6c42\u5b8c\u6210\u540e\u5173\u95ed TCP<\/span><br \/>\n\\\\r\\\\n<\/p>\n<p>\u5de5\u7a0b\u51b3\u7b56&#xff1a; \u5728\u5b9e\u73b0 HTTP \u670d\u52a1\u5668\u65f6&#xff0c;\u6700\u7b80\u5355\u7684\u505a\u6cd5\u662f\u7528 HTTP\/1.0 \u683c\u5f0f\u54cd\u5e94&#xff0c;\u4e0d\u52a0 Connection: keep-alive\u2014\u2014\u6d4f\u89c8\u5668\u6536\u5230 HTTP\/1.0 \u54cd\u5e94\u540e\u9ed8\u8ba4\u5173\u95ed\u8fde\u63a5\u3002\u8fd9\u6837\u505a\u867d\u7136\u6027\u80fd\u7a0d\u4f4e&#xff08;\u6bcf\u4e2a\u8bf7\u6c42\u4e00\u4e2a TCP \u8fde\u63a5&#xff09;&#xff0c;\u4f46\u4ee3\u7801\u903b\u8f91\u6781\u7b80&#xff0c;\u4e0d\u9700\u8981\u5904\u7406\u8fde\u63a5\u590d\u7528\u3001\u8d85\u65f6\u7ba1\u7406\u7b49\u590d\u6742\u95ee\u9898\u3002\u5927\u90e8\u5206\u6559\u5b66\u7528 HTTP \u670d\u52a1\u5668\u90fd\u8fd9\u4e48\u8bbe\u8ba1\u3002<\/p>\n<h3>\u516d\u3001\u5b9e\u73b0 HTTP \u670d\u52a1\u5668\u2014\u2014\u4ece Hello World \u5230\u5b8c\u6574 Web \u540e\u7aef<\/h3>\n<p>\u73b0\u5728\u628a\u6211\u4eec\u4e4b\u524d\u5199\u7684 TCP \u670d\u52a1\u5668\u6846\u67b6\u6539\u9020\u4e3a\u529f\u80fd\u5b8c\u5907\u7684 HTTP \u670d\u52a1\u5668\u3002\u6838\u5fc3\u6d41\u6c34\u7ebf&#xff1a;\u63a5\u6536 \u2192 \u89e3\u6790 \u2192 \u8def\u7531 \u2192 \u5904\u7406 \u2192 \u6784\u9020\u54cd\u5e94 \u2192 \u53d1\u9001\u3002<\/p>\n<p>\u5728\u52a8\u624b\u5199\u4ee3\u7801\u4e4b\u524d&#xff0c;\u5148\u804a\u4e00\u4e2a\u6982\u5ff5\u6027\u95ee\u9898&#xff1a;\u4e3a\u4ec0\u4e48\u4f60\u8981\u624b\u5199 HTTP \u670d\u52a1\u5668&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u7528\u73b0\u6210\u7684&#xff1f; \u7b54\u6848\u4e0d\u662f&#034;\u9020\u8f6e\u5b50&#034;&#xff0c;\u800c\u662f\u7a7f\u900f\u62bd\u8c61\u5c42\u3002\u4f7f\u7528 Flask \u6216 Express \u65f6&#xff0c;\u4f60\u5199 &#064;app.route(&#039;\/&#039;) \u7136\u540e\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u4e00\u5207\u90fd\u5f88\u7b80\u5355\u2014\u2014\u4f46\u4f60\u4e5f\u5b8c\u5168\u4e0d\u77e5\u9053\u6d4f\u89c8\u5668\u53d1\u6765\u7684\u539f\u59cb HTTP \u62a5\u6587\u957f\u4ec0\u4e48\u6837\u3001Header \u91cc\u6709\u4ec0\u4e48\u3001Body \u600e\u4e48\u88ab\u89e3\u6790\u7684\u3002\u5f53\u4f60\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u9047\u5230\u4e00\u4e2a\u5947\u602a\u7684\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u95ee\u9898&#xff08;\u6bd4\u5982\u67d0\u65e7\u7248 IE \u53d1\u6765\u7684\u8bf7\u6c42 Header \u91cc\u591a\u4e86\u4e00\u4e2a\u4ece\u672a\u89c1\u8fc7\u7684\u5b57\u6bb5\u5bfc\u81f4\u89e3\u6790\u5931\u8d25&#xff09;&#xff0c;\u4f60\u7ffb\u904d\u6846\u67b6\u6587\u6863\u4e5f\u627e\u4e0d\u5230\u7b54\u6848\u2014\u2014\u56e0\u4e3a\u6846\u67b6\u628a\u8fd9\u4e9b\u7ec6\u8282\u5168\u90e8\u5c01\u88c5\u6389\u4e86\u3002\u624b\u5199\u4e00\u6b21 HTTP \u670d\u52a1\u5668\u7684\u4ef7\u503c\u5728\u4e8e&#xff1a;\u4f60\u4ee5\u540e\u7528\u4efb\u4f55 Web \u6846\u67b6\u65f6&#xff0c;\u8111\u5b50\u91cc\u90fd\u80fd\u6d6e\u73b0\u51fa\u5e95\u5c42\u5728\u505a\u4ec0\u4e48\u3002 \u8fd9\u79cd\u5fc3\u667a\u6a21\u578b\u4e00\u65e6\u5efa\u7acb&#xff0c;\u8c03\u8bd5\u6548\u7387\u7684\u63d0\u5347\u8fdc\u8d85\u5199\u4ee3\u7801\u7684\u90a3\u51e0\u4e2a\u5c0f\u65f6\u3002<\/p>\n<h4>6.1 Hello World\u2014\u2014\u6700\u5c0f\u53ef\u884c\u7248\u672c<\/h4>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;sys\/socket.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;netinet\/in.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;arpa\/inet.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;string.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdlib.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> argc<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span> argv<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>argc <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;usage: .\/http_server [ip] [port]\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ TCP \u4e09\u90e8\u66f2&#xff1a;socket \u2192 bind \u2192 listen<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> fd <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">socket<\/span><span class=\"token punctuation\">(<\/span>AF_INET<span class=\"token punctuation\">,<\/span> SOCK_STREAM<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>fd <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;socket&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">sockaddr_in<\/span> addr<span class=\"token punctuation\">;<\/span><br \/>\n    addr<span class=\"token punctuation\">.<\/span>sin_family <span class=\"token operator\">&#061;<\/span> AF_INET<span class=\"token punctuation\">;<\/span><br \/>\n    addr<span class=\"token punctuation\">.<\/span>sin_addr<span class=\"token punctuation\">.<\/span>s_addr <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">inet_addr<\/span><span class=\"token punctuation\">(<\/span>argv<span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    addr<span class=\"token punctuation\">.<\/span>sin_port <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">htons<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">atoi<\/span><span class=\"token punctuation\">(<\/span>argv<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">sockaddr<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&amp;<\/span>addr<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>addr<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;bind&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">listen<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;listen&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">sockaddr_in<\/span> client_addr<span class=\"token punctuation\">;<\/span><br \/>\n        socklen_t len <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>client_addr<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> client_fd <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">accept<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">sockaddr<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&amp;<\/span>client_addr<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>len<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>client_fd <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;accept&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">continue<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u63a5\u6536\u5b8c\u6574\u7684 HTTP \u8bf7\u6c42<\/span><br \/>\n        <span class=\"token keyword\">char<\/span> input_buf<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        ssize_t read_size <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">read<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">,<\/span> input_buf<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>input_buf<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>read_size <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">continue<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u6253\u5370\u8bf7\u6c42\u5185\u5bb9&#xff08;\u8c03\u8bd5\u7528&#xff09;<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;[Request]\\\\n%s\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> input_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u6784\u9020 HTTP \u54cd\u5e94&#xff1a;HTTP\/1.0 200 &#043; Content-Length &#043; Body<\/span><br \/>\n        <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span> hello <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;&lt;h1&gt;hello world&lt;\/h1&gt;&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">char<\/span> response<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;HTTP\/1.0 200 OK\\\\n&#034;<\/span><br \/>\n                <span class=\"token string\">&#034;Content-Length: %lu\\\\n&#034;<\/span><br \/>\n                <span class=\"token string\">&#034;\\\\n&#034;<\/span><br \/>\n                <span class=\"token string\">&#034;%s&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>hello<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> hello<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">,<\/span> response<span class=\"token punctuation\">,<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u6bcf\u4e00\u6b65\u90fd\u6709\u8bb2\u7a76&#xff1a;<\/p>\n<table>\n<tr>\u6b65\u9aa4\u4ee3\u7801\u4e3a\u4ec0\u4e48\u8fd9\u6837\u5199<\/tr>\n<tbody>\n<tr>\n<td>input_buf[1024*10]<\/td>\n<td>10KB \u7f13\u51b2\u533a\u4e00\u6b21\u6027\u8bfb<\/td>\n<td>HTTP \u8bf7\u6c42\u901a\u5e38\u5c0f\u4e8e 10KB&#xff0c;\u907f\u514d\u590d\u6742\u7684\u5faa\u73af\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>HTTP\/1.0 \u800c\u975e 1.1<\/td>\n<td>\u54cd\u5e94\u884c\u7528 HTTP\/1.0<\/td>\n<td>\u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u6211\u4e0d\u4f1a keep-alive&#034;&#xff0c;\u6d4f\u89c8\u5668\u4e0d\u4f1a\u5728\u540c\u4e00\u4e2a TCP \u8fde\u63a5\u4e0a\u53d1\u7b2c\u4e8c\u6761\u8bf7\u6c42<\/td>\n<\/tr>\n<tr>\n<td>Content-Length<\/td>\n<td>\u7cbe\u786e\u8ba1\u7b97 strlen(hello)<\/td>\n<td>\u6d4f\u89c8\u5668\u9700\u8981\u77e5\u9053 Body \u4f55\u65f6\u7ed3\u675f\u3002\u4e0d\u5199\u8fd9\u4e2a\u4f1a\u5bfc\u81f4\u6d4f\u89c8\u5668\u6302\u8d77\u7b49\u5f85<\/td>\n<\/tr>\n<tr>\n<td>\u4e24\u4e2a \\\\n\\\\n<\/td>\n<td>Header \u548c Body \u4e4b\u95f4<\/td>\n<td>\u7b2c\u4e00\u4e2a \\\\n \u662f Content-Length \u884c\u7684\u7ed3\u675f&#xff0c;\u7b2c\u4e8c\u4e2a \\\\n \u662f\u6807\u5fd7 Header \u7ed3\u675f\u7684\u7a7a\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7f16\u8bd1\u8fd0\u884c\u540e&#xff0c;\u5728\u6d4f\u89c8\u5668\u8f93\u5165 http:\/\/127.0.0.1:9090&#xff0c;\u5c31\u80fd\u770b\u5230 \u201chello world\u201d \u9875\u9762\u3002\u670d\u52a1\u7aef\u7ec8\u7aef\u4f1a\u6253\u5370\u6d4f\u89c8\u5668\u53d1\u6765\u7684\u5b8c\u6574\u8bf7\u6c42\u6587\u672c\u2014\u2014\u8fd9\u662f\u7406\u89e3 HTTP \u534f\u8bae\u6700\u597d\u7684\u65b9\u5f0f&#xff1a;\u4eb2\u773c\u770b\u5230\u6d4f\u89c8\u5668\u5230\u5e95\u53d1\u4e86\u4ec0\u4e48\u3002<\/p>\n<p>\u8fd9\u4e2a Hello World \u7248\u672c\u867d\u7136\u53ea\u6709\u51e0\u5341\u884c&#xff0c;\u4f46\u5b83\u5b8c\u6574\u5730\u8d70\u901a\u4e86 HTTP \u901a\u4fe1\u7684\u5168\u94fe\u8def\u3002\u505c\u4e0b\u6765\u601d\u8003\u4e00\u4e0b\u6d4f\u89c8\u5668\u548c\u4f60\u5199\u7684\u670d\u52a1\u5668\u4e4b\u95f4\u53d1\u751f\u4e86\u4ec0\u4e48&#xff1a;\u6d4f\u89c8\u5668\u89e3\u6790\u4f60\u5728\u5730\u5740\u680f\u8f93\u5165\u7684 http:\/\/127.0.0.1:9090&#xff0c;\u63d0\u53d6\u51fa IP \u5730\u5740 127.0.0.1 \u548c\u7aef\u53e3 9090&#xff0c;\u901a\u8fc7 TCP \u4e09\u6b21\u63e1\u624b\u4e0e\u4f60\u7684\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5&#xff0c;\u7136\u540e\u53d1\u9001\u4e00\u4e2a\u7b26\u5408 HTTP\/1.1 \u6807\u51c6\u7684\u8bf7\u6c42\u62a5\u6587\u3002\u4f60\u7684\u670d\u52a1\u5668\u8c03\u7528 read \u628a\u5b83\u8bfb\u51fa\u6765&#xff0c;\u8c03\u7528 sprintf \u62fc\u63a5\u4e86\u4e00\u4e2a\u7b26\u5408 HTTP\/1.0 \u6807\u51c6\u7684\u54cd\u5e94\u62a5\u6587&#xff0c;\u8c03\u7528 write \u53d1\u56de\u53bb\u3002\u6d4f\u89c8\u5668\u6536\u5230\u540e\u89e3\u6790\u72b6\u6001\u884c HTTP\/1.0 200 OK\u2014\u2014\u786e\u8ba4\u8bf7\u6c42\u6210\u529f&#xff0c;\u89e3\u6790 Content-Length: 20\u2014\u2014\u77e5\u9053 Body \u6709 20 \u5b57\u8282&#xff0c;\u7136\u540e\u4ece\u7a7a\u884c\u4e4b\u540e\u53d6\u51fa &lt;h1&gt;hello world&lt;\/h1&gt;&#xff0c;\u4ea4\u7ed9 HTML \u6e32\u67d3\u5f15\u64ce\u3002\u6574\u4e2a\u8fc7\u7a0b\u6d89\u53ca\u5e94\u7528\u5c42\u3001\u4f20\u8f93\u5c42\u3001\u7f51\u7edc\u5c42\u3001\u94fe\u8def\u5c42\u56db\u5c42\u534f\u8bae\u6808\u7684\u534f\u4f5c&#xff0c;\u4f46\u7ad9\u5728 HTTP \u5c42\u9762\u7684\u4f60&#xff0c;\u53ea\u9700\u8981\u5173\u5fc3\u4e24\u4ef6\u4e8b&#xff1a;\u6536\u5230\u7684\u5b57\u7b26\u4e32\u600e\u4e48\u89e3\u6790&#xff0c;\u8981\u56de\u7684\u5b57\u7b26\u4e32\u600e\u4e48\u62fc\u3002 \u8fd9\u5c31\u662f\u534f\u8bae\u5206\u5c42\u7684\u5a01\u529b\u2014\u2014\u4e0b\u5c42\u8d1f\u8d23\u53ef\u9760\u4f20\u8f93&#xff0c;\u4e0a\u5c42\u53ea\u5173\u5fc3\u8bed\u4e49\u3002<\/p>\n<h4>6.2 \u6269\u5c55\u4e00&#xff1a;\u652f\u6301\u8bf7\u6c42\u8def\u5f84\u89e3\u6790\u548c\u9759\u6001\u6587\u4ef6\u8fd4\u56de<\/h4>\n<p>\u4e0b\u9762\u6dfb\u52a0\u4e0a\u4e00\u7bc7\u4e2d\u7684 GetFileContent \u51fd\u6570&#xff0c;\u6839\u636e\u6d4f\u89c8\u5668\u8bf7\u6c42\u7684\u8def\u5f84\u8fd4\u56de\u5bf9\u5e94\u7684 HTML \u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u8bfb\u53d6\u4e8c\u8fdb\u5236\u6587\u4ef6\u5185\u5bb9<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">GetFileContent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>path<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>ifstream <span class=\"token function\">in<\/span><span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">,<\/span> std<span class=\"token double-colon punctuation\">::<\/span>ios<span class=\"token double-colon punctuation\">::<\/span>binary<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>in<span class=\"token punctuation\">.<\/span><span class=\"token function\">is_open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    in<span class=\"token punctuation\">.<\/span><span class=\"token function\">seekg<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> in<span class=\"token punctuation\">.<\/span>end<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> filesize <span class=\"token operator\">&#061;<\/span> in<span class=\"token punctuation\">.<\/span><span class=\"token function\">tellg<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    in<span class=\"token punctuation\">.<\/span><span class=\"token function\">seekg<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> in<span class=\"token punctuation\">.<\/span>beg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    std<span class=\"token double-colon punctuation\">::<\/span>string content<span class=\"token punctuation\">;<\/span><br \/>\n    content<span class=\"token punctuation\">.<\/span><span class=\"token function\">resize<\/span><span class=\"token punctuation\">(<\/span>filesize<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    in<span class=\"token punctuation\">.<\/span><span class=\"token function\">read<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span>content<span class=\"token punctuation\">.<\/span><span class=\"token function\">c_str<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> filesize<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    in<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> content<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u6790 HTTP \u8bf7\u6c42\u9996\u884c&#xff0c;\u63d0\u53d6\u8def\u5f84<\/span><br \/>\n<span class=\"token comment\">\/\/ &#034;GET \/index.html HTTP\/1.1\\\\r\\\\n&#8230;&#034; \u2192 &#034;\/index.html&#034;<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">ParsePath<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>request<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    size_t start <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token char\">&#039; &#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u65b9\u6cd5\u540e\u7684\u7b2c\u4e00\u4e2a\u7a7a\u683c<\/span><br \/>\n    size_t end <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token char\">&#039; &#039;<\/span><span class=\"token punctuation\">,<\/span> start<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ URL \u540e\u7684\u7a7a\u683c<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>start <span class=\"token operator\">&#061;&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos <span class=\"token operator\">||<\/span> end <span class=\"token operator\">&#061;&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">substr<\/span><span class=\"token punctuation\">(<\/span>start<span class=\"token punctuation\">,<\/span> end <span class=\"token operator\">&#8211;<\/span> start<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6839\u636e\u6587\u4ef6\u540e\u7f00\u5224\u65ad Content-Type<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">GetContentType<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>path<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.html&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;text\/html&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.css&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;text\/css&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.js&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>   <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;application\/javascript&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.png&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;image\/png&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.jpg&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span> path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.jpeg&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;image\/jpeg&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">ends_with<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.json&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;application\/json&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u9ed8\u8ba4<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5728 accept \u62ff\u5230 client_fd \u4e4b\u540e&#xff1a;<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string path <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">ParsePath<\/span><span class=\"token punctuation\">(<\/span>input_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span> path <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/index.html&#034;<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u9ed8\u8ba4\u9996\u9875<\/span><\/p>\n<p>std<span class=\"token double-colon punctuation\">::<\/span>string root_dir <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;.\/www&#034;<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ Web \u6839\u76ee\u5f55<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string full_path <span class=\"token operator\">&#061;<\/span> root_dir <span class=\"token operator\">&#043;<\/span> path<span class=\"token punctuation\">;<\/span><\/p>\n<p>std<span class=\"token double-colon punctuation\">::<\/span>string content <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetFileContent<\/span><span class=\"token punctuation\">(<\/span>full_path<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>content<span class=\"token punctuation\">.<\/span><span class=\"token function\">empty<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6587\u4ef6\u4e0d\u5b58\u5728 \u2192 404<\/span><br \/>\n    <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span> body <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;&lt;h1&gt;404 Not Found&lt;\/h1&gt;&lt;p&gt;The requested URL was not found on this server.&lt;\/p&gt;&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> response<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;HTTP\/1.0 404 Not Found\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;Content-Type: text\/html\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;Content-Length: %lu\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;%s&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>body<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> body<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">,<\/span> response<span class=\"token punctuation\">,<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">else<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6587\u4ef6\u5b58\u5728 \u2192 200 &#043; \u6b63\u786e\u7684 Content-Type<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>string ctype <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetContentType<\/span><span class=\"token punctuation\">(<\/span>full_path<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> response_header<span class=\"token punctuation\">[<\/span><span class=\"token number\">512<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>response_header<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;HTTP\/1.0 200 OK\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;Content-Type: %s\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;Content-Length: %lu\\\\n&#034;<\/span><br \/>\n            <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            ctype<span class=\"token punctuation\">.<\/span><span class=\"token function\">c_str<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> content<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5148\u53d1 Header<\/span><br \/>\n    <span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">,<\/span> response_header<span class=\"token punctuation\">,<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>response_header<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u518d\u53d1 Body&#xff08;\u4e8c\u8fdb\u5236\u5b89\u5168&#xff0c;\u7528 write \u800c\u975e\u5b57\u7b26\u4e32\u51fd\u6570&#xff09;<\/span><br \/>\n    <span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span>client_fd<span class=\"token punctuation\">,<\/span> content<span class=\"token punctuation\">.<\/span><span class=\"token function\">c_str<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> content<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u5199 Body \u8981\u7528 write(content.c_str(), content.size()) \u800c\u4e0d\u662f sprintf&#xff1f; \u56e0\u4e3a HTML\/CSS\/JS\/\u56fe\u7247\u6587\u4ef6\u5185\u5bb9\u4e2d\u53ef\u80fd\u5305\u542b \\\\0&#xff08;\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff09;\u6216\u5bfc\u81f4 sprintf \u683c\u5f0f\u4e32\u95ee\u9898\u3002content.size() \u662f\u4e8c\u8fdb\u5236\u5b89\u5168\u7684\u957f\u5ea6\u3002<\/p>\n<p>\u8fd9\u4e2a\u6269\u5c55\u8ba9\u670d\u52a1\u5668\u4ece&#034;\u53ea\u4f1a\u8bf4 Hello World&#034;\u8fdb\u5316\u5230\u4e86&#034;\u80fd\u63d0\u4f9b\u4efb\u4f55\u6587\u4ef6&#034;\u3002\u8fd9\u6b63\u662f Web \u670d\u52a1\u5668\u6700\u539f\u59cb\u7684\u529f\u80fd\u2014\u2014\u9759\u6001\u6587\u4ef6\u670d\u52a1\u3002Nginx \u548c Apache \u7684\u6838\u5fc3\u5de5\u4f5c\u5c31\u662f\u505a\u8fd9\u4ef6\u4e8b&#xff1a;\u6839\u636e\u8bf7\u6c42 URL \u5728\u78c1\u76d8\u4e0a\u627e\u5230\u5bf9\u5e94\u6587\u4ef6&#xff0c;\u8bbe\u7f6e\u6b63\u786e\u7684 Content-Type&#xff0c;\u7136\u540e\u53d1\u51fa\u53bb\u3002\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u6700\u7b80\u7248\u672c&#xff0c;\u4f46\u5b83\u5df2\u7ecf\u5305\u542b\u4e86\u751f\u4ea7\u7ea7 Web \u670d\u52a1\u5668\u7684\u6838\u5fc3\u903b\u8f91&#xff1a;\u8def\u5f84\u89e3\u6790\u3001\u6587\u4ef6\u7cfb\u7edf\u5b89\u5168&#xff08;\u9632\u6b62\u76ee\u5f55\u7a7f\u8d8a&#xff09;\u3001MIME \u7c7b\u578b\u5339\u914d\u3001\u4e8c\u8fdb\u5236\u5b89\u5168\u4f20\u8f93\u3002\u7406\u89e3\u4e86\u8fd9\u4e2a&#xff0c;\u4f60\u5c31\u7406\u89e3\u4e86 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d root \/var\/www\/html; \u5230\u5e95\u505a\u4e86\u4ec0\u4e48\u3002<\/p>\n<h4>6.3 \u6269\u5c55\u4e8c&#xff1a;\u652f\u6301 POST \u8bf7\u6c42\u2014\u2014\u89e3\u6790\u8868\u5355\u548c JSON<\/h4>\n<p>POST \u7684\u6570\u636e\u5728 Body \u4e2d\u3002\u5173\u952e\u6b65\u9aa4&#xff1a;\u89e3\u6790 Content-Length \u2192 \u8bfb\u53d6 Body \u2192 \u6839\u636e Content-Type \u9009\u62e9\u89e3\u6790\u65b9\u5f0f\u3002<\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u6790 POST Body<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">GetContentLength<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>request<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span> key <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;Content-Length: &#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    size_t pos <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pos <span class=\"token operator\">&#061;&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    pos <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    size_t end <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> pos<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> std<span class=\"token double-colon punctuation\">::<\/span><span class=\"token function\">stoi<\/span><span class=\"token punctuation\">(<\/span>request<span class=\"token punctuation\">.<\/span><span class=\"token function\">substr<\/span><span class=\"token punctuation\">(<\/span>pos<span class=\"token punctuation\">,<\/span> end <span class=\"token operator\">&#8211;<\/span> pos<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u83b7\u53d6 Header \u7ed3\u675f\u4f4d\u7f6e\u540e\u7684 Body<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">GetBody<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>request<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    size_t pos <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\\\\r\\\\n\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7a7a\u884c<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pos <span class=\"token operator\">&#061;&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> request<span class=\"token punctuation\">.<\/span><span class=\"token function\">substr<\/span><span class=\"token punctuation\">(<\/span>pos <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8df3\u8fc7 &#034;\\\\r\\\\n\\\\r\\\\n&#034;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u6790 URL \u7f16\u7801\u7684\u8868\u5355\u6570\u636e: &#034;key1&#061;value1&amp;key2&#061;value2&#034;<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>map<span class=\"token operator\">&lt;<\/span>std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token punctuation\">,<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">ParseFormData<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>body<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>map<span class=\"token operator\">&lt;<\/span>std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token punctuation\">,<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token operator\">&gt;<\/span> result<span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>istringstream <span class=\"token function\">iss<\/span><span class=\"token punctuation\">(<\/span>body<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token double-colon punctuation\">::<\/span>string pair<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>std<span class=\"token double-colon punctuation\">::<\/span><span class=\"token function\">getline<\/span><span class=\"token punctuation\">(<\/span>iss<span class=\"token punctuation\">,<\/span> pair<span class=\"token punctuation\">,<\/span> <span class=\"token char\">&#039;&amp;&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        size_t eq <span class=\"token operator\">&#061;<\/span> pair<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token char\">&#039;&#061;&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>eq <span class=\"token operator\">!&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos<span class=\"token punctuation\">)<\/span><br \/>\n            result<span class=\"token punctuation\">[<\/span>pair<span class=\"token punctuation\">.<\/span><span class=\"token function\">substr<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> eq<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> pair<span class=\"token punctuation\">.<\/span><span class=\"token function\">substr<\/span><span class=\"token punctuation\">(<\/span>eq <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> result<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u4f7f\u7528\u793a\u4f8b&#xff1a;\u5904\u7406\u767b\u5f55\u8868\u5355\u7684 POST \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">int<\/span> content_length <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetContentLength<\/span><span class=\"token punctuation\">(<\/span>input_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string body <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetBody<\/span><span class=\"token punctuation\">(<\/span>input_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> form <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">ParseFormData<\/span><span class=\"token punctuation\">(<\/span>body<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>std<span class=\"token double-colon punctuation\">::<\/span>string username <span class=\"token operator\">&#061;<\/span> form<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;username&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string password <span class=\"token operator\">&#061;<\/span> form<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;password&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u9a8c\u8bc1\u903b\u8f91&#8230;<\/span><\/p>\n<h4>6.4 \u6269\u5c55\u4e09&#xff1a;\u5b8c\u6574\u7684 HTTP \u8bf7\u6c42\u54cd\u5e94\u6d41\u6c34\u7ebf<\/h4>\n<p>\u628a\u4e0a\u8ff0\u5404\u90e8\u5206\u4e32\u8054\u8d77\u6765&#xff0c;\u5c31\u662f\u4e00\u4e2a\u529f\u80fd\u5b8c\u5907\u7684 Web \u670d\u52a1\u5668\u4e3b\u5faa\u73af&#xff1a;<\/p>\n<p>\u2460 read(client_fd) \u2192 \u62ff\u5230 HTTP \u8bf7\u6c42\u6587\u672c<br \/>\n\u2461 ParsePath(request) \u2192 &#034;\/index.html&#034;<br \/>\n\u2462 if GET: \u8bfb\u6587\u4ef6\u8fd4\u56de \u2192 if POST: \u89e3\u6790Body\u6267\u884c\u4e1a\u52a1<br \/>\n\u2463 \u6784\u9020\u54cd\u5e94\u6587\u672c&#xff08;\u72b6\u6001\u884c &#043; Header &#043; \u7a7a\u884c &#043; Body&#xff09;<br \/>\n\u2464 write(client_fd) \u2192 \u6d4f\u89c8\u5668\u6e32\u67d3<br \/>\n\u2465 close(client_fd) \u6216 \u4fdd\u6301\u8fde\u63a5\u7ee7\u7eed\u8bfb<\/p>\n<table>\n<tr>\u6b65\u9aa4\u8f93\u5165\u8f93\u51fa\u6838\u5fc3\u51fd\u6570<\/tr>\n<tbody>\n<tr>\n<td>\u63a5\u6536<\/td>\n<td>TCP \u5b57\u8282\u6d41<\/td>\n<td>HTTP \u8bf7\u6c42\u6587\u672c<\/td>\n<td>read(client_fd, &#8230;)<\/td>\n<\/tr>\n<tr>\n<td>\u89e3\u6790<\/td>\n<td>\u8bf7\u6c42\u6587\u672c<\/td>\n<td>\u65b9\u6cd5 &#043; \u8def\u5f84 &#043; Header &#043; Body<\/td>\n<td>ParsePath GetContentLength<\/td>\n<\/tr>\n<tr>\n<td>\u8def\u7531<\/td>\n<td>\u65b9\u6cd5 &#043; \u8def\u5f84<\/td>\n<td>\u4e1a\u52a1\u5904\u7406\u51fd\u6570<\/td>\n<td>if(path&#061;&#061;&#034;\/api\/user&#034;){&#8230;}<\/td>\n<\/tr>\n<tr>\n<td>\u54cd\u5e94<\/td>\n<td>\u5904\u7406\u7ed3\u679c<\/td>\n<td>HTTP \u54cd\u5e94\u6587\u672c<\/td>\n<td>sprintf(response, &#034;HTTP\/1.0 200&#8230;&#034;)<\/td>\n<\/tr>\n<tr>\n<td>\u53d1\u9001<\/td>\n<td>\u54cd\u5e94\u6587\u672c<\/td>\n<td>TCP \u5b57\u8282\u6d41<\/td>\n<td>write(client_fd, &#8230;)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<hr \/>\n<p>\u5728\u7ee7\u7eed\u4e4b\u524d&#xff0c;\u505c\u4e0b\u6765\u56de\u987e\u4e00\u4e0b\u6211\u4eec\u5230\u76ee\u524d\u4e3a\u6b62\u6784\u5efa\u4e86\u4ec0\u4e48\u3002\u4ece Hello World \u5230 POST \u89e3\u6790&#xff0c;\u8fd9\u4e2a HTTP \u670d\u52a1\u5668\u7684\u529f\u80fd\u6f14\u8fdb\u63ed\u793a\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u5de5\u7a0b\u6a21\u5f0f&#xff1a;\u6bcf\u4e00\u4e2a\u65b0\u529f\u80fd\u90fd\u662f\u5728\u4e0a\u4e00\u4e2a\u7248\u672c\u7684\u57fa\u7840\u4e0a&#xff0c;\u5728\u7279\u5b9a\u73af\u8282\u63d2\u5165\u65b0\u7684\u5904\u7406\u903b\u8f91\u3002 socket\u2192bind\u2192listen\u2192accept \u7684 TCP \u5e95\u5c42\u4ece\u6765\u6ca1\u6709\u53d8\u8fc7&#xff0c;\u53d8\u7684\u662f\u5bf9 HTTP \u62a5\u6587\u7684\u89e3\u6790\u6df1\u5ea6\u548c\u5bf9\u4e0d\u540c\u8def\u5f84\/\u65b9\u6cd5\u7684\u5904\u7406\u7b56\u7565\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u82b1\u90a3\u4e48\u591a\u7cbe\u529b\u5b66 TCP\u2014\u2014\u56e0\u4e3a\u5b83\u662f\u7a33\u5b9a\u7684\u5730\u57fa\u3002\u5730\u57fa\u7262\u56fa\u4e86&#xff0c;\u4e0a\u9762\u76d6\u4ec0\u4e48\u623f\u5b50&#xff08;HTTP\u3001WebSocket\u3001\u81ea\u5b9a\u4e49\u534f\u8bae&#xff09;\u90fd\u53ea\u662f&#034;\u600e\u4e48\u89e3\u6790\u62a5\u6587&#034;\u7684\u95ee\u9898\u3002<\/p>\n<h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u907f\u5751\u6307\u5357<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183615-6a63b09f24dd9.png\" alt=\"QQ20260610-233818\" \/><\/p>\n<h4>7.1 Header \u548c Body \u4e4b\u95f4\u7684\u7a7a\u884c\u4e22\u5931<\/h4>\n<p>\u73b0\u8c61&#xff1a; \u6d4f\u89c8\u5668\u4e00\u76f4\u8f6c\u5708&#xff08;pending&#xff09;&#xff0c;\u670d\u52a1\u5668\u65e5\u5fd7\u663e\u793a\u5df2 write \u4f46\u9875\u9762\u52a0\u8f7d\u4e0d\u51fa\u6765\u3002<\/p>\n<p>\u539f\u56e0&#xff1a; sprintf(response, &#034;HTTP\/1.0 200 OK\\\\r\\\\nContent-Length: 20\\\\r\\\\n%s&#034;, body); \u5c11\u4e86\u4e00\u4e2a \\\\r\\\\n\u2014\u2014\u6d4f\u89c8\u5668\u4ee5\u4e3a Header \u8fd8\u6ca1\u7ed3\u675f&#xff0c;\u4e00\u76f4\u5728\u7b49&#034;\u7a7a\u884c&#034;\u3002<\/p>\n<p>\u89e3\u51b3&#xff1a; sprintf(response, &#034;HTTP\/1.0 200 OK\\\\r\\\\nContent-Length: 20\\\\r\\\\n\\\\r\\\\n%s&#034;, body); \u5728 Content-Length \u884c\u540e\u9762\u5fc5\u987b\u6709\u4e24\u4e2a\u8fde\u7eed\u7684 \\\\r\\\\n\u3002<\/p>\n<h4>7.2 Content-Length \u4e0e\u5b9e\u9645 Body \u957f\u5ea6\u4e0d\u5339\u914d<\/h4>\n<p>\u73b0\u8c61&#xff1a; \u9875\u9762\u5185\u5bb9\u88ab\u622a\u65ad&#xff0c;\u6216\u8005\u6d4f\u89c8\u5668\u663e\u793a&#034;\u8fde\u63a5\u88ab\u91cd\u7f6e&#034;\u3002<\/p>\n<p>\u539f\u56e0&#xff1a; Content-Length \u544a\u8bc9\u6d4f\u89c8\u5668&#034;Body \u6709 500 \u5b57\u8282&#034;&#xff0c;\u4f46\u5b9e\u9645\u53ea\u53d1\u4e86 300 \u5b57\u8282\u3002\u6d4f\u89c8\u5668\u63a5\u6536 300 \u5b57\u8282\u540e\u7ee7\u7eed\u963b\u585e\u7b49\u5f85\u5269\u4e0b 200 \u5b57\u8282\u2014\u2014\u7b49\u4e0d\u5230\u5c31\u4f1a\u8d85\u65f6\u65ad\u5f00\u3002<\/p>\n<p>\u89e3\u51b3&#xff1a; \u7528 strlen(body) \u6216 .size() \u7cbe\u786e\u8ba1\u7b97&#xff0c;\u4e0d\u4f7f\u7528\u786c\u7f16\u7801\u6570\u5b57\u3002\u5bf9\u4e8e\u4e2d\u6587\u5185\u5bb9&#xff0c;\u6ce8\u610f strlen \u8ba1\u7b97\u7684\u662f\u5b57\u8282\u6570\u800c\u975e\u5b57\u7b26\u6570\u3002<\/p>\n<h4>7.3 \u6d4f\u89c8\u5668\u591a\u53d1\u51fa\u4e00\u4e2a \/favicon.ico \u8bf7\u6c42<\/h4>\n<p>\u73b0\u8c61&#xff1a; \u670d\u52a1\u5668\u65e5\u5fd7\u4e2d\u9664\u4e86\u9884\u671f\u7684\u8bf7\u6c42\u4e4b\u5916&#xff0c;\u603b\u6709\u4e00\u4e2a GET \/favicon.ico HTTP\/1.1\u3002<\/p>\n<p>\u539f\u56e0&#xff1a; \u6d4f\u89c8\u5668\u9ed8\u8ba4\u8bf7\u6c42\u7f51\u7ad9\u56fe\u6807\u4ee5\u663e\u793a\u5728\u6807\u7b7e\u9875\u4e0a\u3002\u8fd9\u4e0d\u662f bug&#xff0c;\u662f\u6b63\u5e38\u884c\u4e3a\u3002<\/p>\n<p>\u89e3\u51b3&#xff1a; \u5728\u6839\u76ee\u5f55\u653e\u4e00\u4e2a favicon.ico \u6587\u4ef6&#xff0c;\u6216\u8005\u8fd4\u56de 404 \u5ffd\u7565\u8be5\u65e5\u5fd7\u3002<\/p>\n<h4>7.4 URL \u8def\u5f84\u5305\u542b .. \u5bfc\u81f4\u76ee\u5f55\u7a7f\u8d8a<\/h4>\n<p>\u73b0\u8c61&#xff1a; \u653b\u51fb\u8005\u8bf7\u6c42 GET \/..\/etc\/passwd HTTP\/1.1&#xff0c;\u670d\u52a1\u5668\u8fd4\u56de\u4e86\u7cfb\u7edf\u654f\u611f\u6587\u4ef6\u3002<\/p>\n<p>\u539f\u56e0&#xff1a; \u7b80\u5355\u62fc\u63a5 root_dir &#043; path \u6ca1\u6709\u8fc7\u6ee4 ..&#xff0c;\u5bfc\u81f4\u53ef\u4ee5\u8bbf\u95ee Web \u6839\u76ee\u5f55\u4e4b\u5916\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u89e3\u51b3&#xff1a; \u89e3\u6790\u5b8c\u8def\u5f84\u540e&#xff0c;\u8fc7\u6ee4 .. \u6216\u4f7f\u7528 realpath \u68c0\u67e5\u6700\u7ec8\u8def\u5f84\u662f\u5426\u5728 Web \u6839\u76ee\u5f55\u5185&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u9632\u6b62\u76ee\u5f55\u7a7f\u8d8a\u653b\u51fb<\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token function\">SafePath<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>root<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">const<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string <span class=\"token operator\">&amp;<\/span>path<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7b80\u5355\u65b9\u6848&#xff1a;\u8fc7\u6ee4 &#034;..&#034;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;..&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!&#061;<\/span> std<span class=\"token double-colon punctuation\">::<\/span>string<span class=\"token double-colon punctuation\">::<\/span>npos<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> root <span class=\"token operator\">&#043;<\/span> path<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<h3>\u516b\u3001MIME \u7c7b\u578b\u4e0e Content-Type<\/h3>\n<h4>8.1 \u4e3a\u4ec0\u4e48\u9700\u8981 Content-Type<\/h4>\n<p>\u6d4f\u89c8\u5668\u6536\u5230\u54cd\u5e94 Body \u540e&#xff0c;\u9700\u8981\u5224\u65ad\u8fd9\u662f HTML&#xff08;\u89e3\u6790\u5e76\u6e32\u67d3&#xff09;\u3001\u56fe\u7247&#xff08;\u76f4\u63a5\u663e\u793a&#xff09;\u3001CSS&#xff08;\u89e3\u6790\u540e\u5e94\u7528\u6837\u5f0f&#xff09;\u3001JavaScript&#xff08;\u6267\u884c&#xff09;\u3001\u8fd8\u662f JSON&#xff08;\u4ea4\u7ed9 AJAX \u56de\u8c03&#xff09;\u3002\u8fd9\u4e2a\u5224\u65ad\u7684\u4f9d\u636e\u5c31\u662f Content-Type \u5934\u90e8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183615-6a63b09ff178e.png\" alt=\"QQ20260610-234033\" \/><\/p>\n<table>\n<tr>Content-TypeBody \u5185\u5bb9\u6d4f\u89c8\u5668\u884c\u4e3a<\/tr>\n<tbody>\n<tr>\n<td>text\/html<\/td>\n<td>HTML \u6587\u6863<\/td>\n<td>\u89e3\u6790 DOM \u6811&#xff0c;\u6e32\u67d3\u9875\u9762<\/td>\n<\/tr>\n<tr>\n<td>text\/css<\/td>\n<td>CSS \u6837\u5f0f\u8868<\/td>\n<td>\u5e94\u7528\u6837\u5f0f\u5230\u9875\u9762<\/td>\n<\/tr>\n<tr>\n<td>application\/javascript<\/td>\n<td>JavaScript \u4ee3\u7801<\/td>\n<td>\u4ea4\u7ed9 JS \u5f15\u64ce\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>image\/png<\/td>\n<td>PNG \u56fe\u7247<\/td>\n<td>\u76f4\u63a5\u6e32\u67d3\u663e\u793a<\/td>\n<\/tr>\n<tr>\n<td>application\/json<\/td>\n<td>JSON \u6570\u636e<\/td>\n<td>\u4ea4\u7ed9 fetch \u6216 XMLHttpRequest \u7684\u56de\u8c03<\/td>\n<\/tr>\n<tr>\n<td>application\/x-www-form-urlencoded<\/td>\n<td>URL \u7f16\u7801\u7684\u8868\u5355\u6570\u636e<\/td>\n<td>POST \u8bf7\u6c42 Body \u7684\u9ed8\u8ba4\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>text\/plain<\/td>\n<td>\u7eaf\u6587\u672c<\/td>\n<td>\u6309\u6587\u672c\u539f\u6837\u663e\u793a&#xff0c;\u4e0d\u89e3\u6790<\/td>\n<\/tr>\n<tr>\n<td>multipart\/form-data<\/td>\n<td>\u5305\u542b\u6587\u4ef6\u4e0a\u4f20\u7684\u8868\u5355<\/td>\n<td>\u6d4f\u89c8\u5668\u6309\u8fb9\u754c\u5206\u9694\u7b26\u89e3\u6790\u5404\u5b57\u6bb5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679c\u670d\u52a1\u5668\u4e0d\u8fd4\u56de Content-Type&#xff0c;\u6d4f\u89c8\u5668\u4f1a\u5c1d\u8bd5MIME \u55c5\u63a2&#xff08;\u6839\u636e Body \u7684\u524d\u51e0\u4e2a\u5b57\u8282\u731c\u6d4b\u7c7b\u578b&#xff09;&#xff0c;\u4f46\u731c\u9519\u662f\u5e38\u6709\u7684\u4e8b\u3002\u6c38\u8fdc\u4e0d\u8981\u4f9d\u8d56\u6d4f\u89c8\u5668\u7684\u731c\u6d4b\u2014\u2014\u81ea\u5df1\u663e\u5f0f\u8bbe\u7f6e\u6b63\u786e\u7684 Content-Type\u3002<\/p>\n<h4>8.2 \u5e38\u89c1\u7684 Content-Type \u573a\u666f\u5bf9\u7167<\/h4>\n<table>\n<tr>\u573a\u666f\u6b63\u786e\u7684 Content-Type<\/tr>\n<tbody>\n<tr>\n<td>\u8fd4\u56de\u4e00\u4e2a HTML \u9875\u9762<\/td>\n<td>text\/html; charset&#061;utf-8<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de API \u7684 JSON \u54cd\u5e94<\/td>\n<td>application\/json<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u4e00\u6bb5 CSS \u6587\u4ef6<\/td>\n<td>text\/css<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u4e00\u5f20\u56fe\u7247&#xff08;\u6d4f\u89c8\u5668\u76f4\u63a5\u663e\u793a&#xff09;<\/td>\n<td>image\/png \u6216 image\/jpeg<\/td>\n<\/tr>\n<tr>\n<td>\u8ba9\u6d4f\u89c8\u5668\u4e0b\u8f7d\u6587\u4ef6\u800c\u975e\u76f4\u63a5\u663e\u793a<\/td>\n<td>application\/octet-stream&#xff08;\u901a\u7528\u4e8c\u8fdb\u5236\u6d41&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>POST \u8868\u5355\u63d0\u4ea4&#xff08;&lt;form&gt; \u6807\u7b7e&#xff09;<\/td>\n<td>application\/x-www-form-urlencoded<\/td>\n<\/tr>\n<tr>\n<td>POST JSON \u6570\u636e&#xff08;AJAX\/fetch&#xff09;<\/td>\n<td>application\/json<\/td>\n<\/tr>\n<tr>\n<td>\u4e0a\u4f20\u6587\u4ef6&#xff08;&lt;input type&#061;&#034;file&#034;&gt;&#xff09;<\/td>\n<td>multipart\/form-data<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e5d\u3001\u6d4f\u89c8\u5668\u7f13\u5b58\u673a\u5236\u2014\u2014304 Not Modified \u7684\u539f\u7406<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183616-6a63b0a0daa76.png\" alt=\"QQ20260610-234232\" \/><\/p>\n<p>\u7406\u89e3 HTTP \u7f13\u5b58\u80fd\u5e2e\u4f60\u5199\u51fa\u79d2\u5f00\u7684\u9875\u9762&#xff0c;\u4e5f\u80fd\u5e2e\u4f60\u6392\u67e5&#034;\u660e\u660e\u6539\u4e86\u4ee3\u7801\u4e3a\u4ec0\u4e48\u6d4f\u89c8\u5668\u8fd8\u662f\u663e\u793a\u65e7\u7684&#034;\u8fd9\u7c7b\u95ee\u9898\u3002<\/p>\n<p>\u7f13\u5b58\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u89e3\u51b3\u6027\u80fd\u95ee\u9898\u7684\u4e07\u80fd\u94a5\u5319\u2014\u2014\u4ece CPU \u7684\u591a\u7ea7\u7f13\u5b58\u5230 Redis \u7684\u5185\u5b58\u7f13\u5b58&#xff0c;\u518d\u5230 CDN \u7684\u8fb9\u7f18\u8282\u70b9&#xff0c;\u672c\u8d28\u4e0a\u90fd\u662f&#034;\u628a\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u653e\u5728\u79bb\u4f7f\u7528\u8005\u66f4\u8fd1\u7684\u5730\u65b9&#034;\u3002HTTP \u7684\u7f13\u5b58\u673a\u5236\u662f\u8fd9\u4e00\u601d\u60f3\u7684\u7ecf\u5178\u5b9e\u73b0&#xff1a;\u6d4f\u89c8\u5668\u7b2c\u4e00\u6b21\u8bf7\u6c42\u8d44\u6e90\u65f6\u62ff\u5230 Last-Modified \u6216 ETag&#xff0c;\u4e0b\u6b21\u8bf7\u6c42\u65f6\u5e26\u4e0a If-Modified-Since \u6216 If-None-Match&#xff0c;\u670d\u52a1\u5668\u6bd4\u8f83\u540e\u53d1\u73b0\u8d44\u6e90\u6ca1\u53d8&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u96f6 Body \u7684 304 \u54cd\u5e94\u2014\u2014\u51e0\u6beb\u79d2\u7684\u5f80\u8fd4\u65f6\u95f4\u76f8\u6bd4\u51e0\u767e\u6beb\u79d2\u7684\u5b8c\u6574\u4e0b\u8f7d&#xff0c;\u7528\u6237\u4f53\u9a8c\u5929\u5dee\u5730\u522b\u3002\u66f4\u6fc0\u8fdb\u7684\u505a\u6cd5\u662f Cache-Control: max-age&#061;31536000\u2014\u2014\u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u8fd9\u4e2a\u8d44\u6e90\u4e00\u5e74\u5185\u4e0d\u4f1a\u53d8&#xff0c;\u76f4\u63a5\u672c\u5730\u8bfb\u53d6&#xff0c;\u522b\u6765\u95ee\u6211&#034;\u3002\u914d\u5408\u524d\u7aef\u6784\u5efa\u5de5\u5177\u7ed9\u6587\u4ef6\u540d\u52a0 hash&#xff08;app.a3f2b1c.js&#xff09;&#xff0c;\u53ef\u4ee5\u505a\u5230&#034;\u53ea\u8981\u5185\u5bb9\u53d8\u4e86\u6587\u4ef6\u540d\u5c31\u53d8&#xff0c;\u53ea\u8981\u6587\u4ef6\u540d\u6ca1\u53d8\u5185\u5bb9\u5c31\u4e0d\u4f1a\u53d8&#034;\u7684\u5b8c\u7f8e\u7f13\u5b58\u7b56\u7565\u3002<\/p>\n<h4>9.1 \u57fa\u4e8e\u65f6\u95f4\u7684\u7f13\u5b58&#xff1a;Last-Modified &#043; If-Modified-Since<\/h4>\n<p>\u9996\u6b21\u8bf7\u6c42&#xff1a;<br \/>\n  \u6d4f\u89c8\u5668 \u2192 GET \/style.css HTTP\/1.1<br \/>\n  \u670d\u52a1\u5668 \u2192 200 OK &#043; Last-Modified: Mon, 23 Jan 2023 13:27:56 GMT &#043; Body(style.css)<\/p>\n<p>\u7b2c\u4e8c\u6b21\u8bf7\u6c42&#xff08;\u6d4f\u89c8\u5668\u7f13\u5b58\u672a\u8fc7\u671f&#xff0c;\u4f46\u9700\u8981\u9a8c\u8bc1&#xff09;&#xff1a;<br \/>\n  \u6d4f\u89c8\u5668 \u2192 GET \/style.css HTTP\/1.1 &#043; If-Modified-Since: Mon, 23 Jan 2023 13:27:56 GMT<br \/>\n  \u670d\u52a1\u5668\u68c0\u67e5\u6587\u4ef6\u4fee\u6539\u65f6\u95f4&#xff1a;<br \/>\n    \u5982\u679c\u672a\u4fee\u6539 \u2192 304 Not Modified&#xff08;\u65e0 Body&#xff0c;\u6781\u5c0f\u54cd\u5e94&#xff0c;\u6d4f\u89c8\u5668\u76f4\u63a5\u7528\u672c\u5730\u7f13\u5b58&#xff09;<br \/>\n    \u5982\u679c\u5df2\u4fee\u6539 \u2192 200 OK &#043; \u65b0\u7684 Last-Modified &#043; \u65b0\u7684 Body<\/p>\n<p>304 \u54cd\u5e94\u4f53\u4e3a\u7a7a\u2014\u2014\u5b83\u7684\u4f5c\u7528\u53ea\u662f\u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u4f60\u7684\u7f13\u5b58\u6ca1\u95ee\u9898&#xff0c;\u7ee7\u7eed\u7528&#034;\u3002\u8fd9\u6bd4\u91cd\u65b0\u53d1\u9001\u6574\u4e2a\u6587\u4ef6\u5feb\u51e0\u5341\u500d\u3002<\/p>\n<h4>9.2 \u57fa\u4e8e\u5185\u5bb9\u7684\u7f13\u5b58&#xff1a;ETag &#043; If-None-Match<\/h4>\n<p>Last-Modified \u7684\u95ee\u9898&#xff1a;\u6587\u4ef6\u5185\u5bb9\u6539\u4e86\u4f46\u53c8\u6539\u56de\u53bb\u4e86&#xff08;\u6bd4\u5982\u64a4\u9500\u7f16\u8f91&#xff09;&#xff0c;\u4fee\u6539\u65f6\u95f4\u53d8\u4e86\u4f46\u5185\u5bb9\u6ca1\u53d8\u3002ETag \u7528\u5185\u5bb9\u7684\u54c8\u5e0c\u503c\u4ee3\u66ff\u65f6\u95f4&#xff1a;<\/p>\n<p>ETag: &#034;3f80f-1b6-5f4e2512a4100&#034;  \u2190 \u6587\u4ef6\u5185\u5bb9\u7684 hash&#xff08;\u901a\u5e38\u662f MD5 \u6216 SHA1&#xff09;<\/p>\n<p>\u6d4f\u89c8\u5668\u4e0b\u6b21\u8bf7\u6c42\u65f6\u5e26 If-None-Match: &#034;3f80f-1b6-5f4e2512a4100&#034;&#xff0c;\u670d\u52a1\u5668\u6bd4\u5bf9 hash\u2014\u2014\u76f8\u540c\u8fd4\u56de 304&#xff0c;\u4e0d\u540c\u8fd4\u56de 200 &#043; \u65b0\u5185\u5bb9 &#043; \u65b0 ETag\u3002<\/p>\n<h4>9.3 Cache-Control&#xff1a;\u8ba9\u6d4f\u89c8\u5668\u8df3\u8fc7&#034;\u9a8c\u8bc1&#034;\u6b65\u9aa4<\/h4>\n<p>\u5bf9\u4e8e\u7edd\u5bf9\u4e0d\u4f1a\u53d8\u7684\u8d44\u6e90&#xff08;\u5982\u5e26\u7248\u672c\u53f7\u7684\u9759\u6001\u6587\u4ef6 app.v1.2.3.js&#xff09;&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u76f4\u63a5\u7f13\u5b58&#xff0c;\u4e0d\u7528\u6bcf\u6b21\u9a8c\u8bc1&#034;&#xff1a;<\/p>\n<p>Cache-Control: max-age&#061;31536000   \u2190 \u7f13\u5b58\u4e00\u5e74&#xff08;31536000 \u79d2&#xff09;<\/p>\n<p>\u8fd9\u6837\u6d4f\u89c8\u5668\u5728\u4e00\u5e74\u4e4b\u5185\u90fd\u4e0d\u4f1a\u4e3a\u8fd9\u4e2a\u8d44\u6e90\u53d1\u9001 HTTP \u8bf7\u6c42\u2014\u2014\u9875\u9762\u52a0\u8f7d\u79d2\u51fa\u3002<\/p>\n<hr \/>\n<h3>\u603b\u7ed3<\/h3>\n<p>HTTP \u534f\u8bae\u7684\u6838\u5fc3\u5c31\u662f\u8868\u683c\u5f0f\u7684\u4e1c\u897f\u2014\u2014\u8bb0\u4f4f\u8fd9\u4e2a\u6a21\u677f\u4f60\u5c31\u6c38\u8fdc\u4f1a\u624b\u5199 HTTP&#xff1a;<\/p>\n<table>\n<tr>\u5361\u7247\u683c\u5f0f\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u8bf7\u6c42\u884c<\/td>\n<td>\u65b9\u6cd5 URL \u7248\u672c<\/td>\n<td>GET \/index.html HTTP\/1.1<\/td>\n<\/tr>\n<tr>\n<td>\u72b6\u6001\u884c<\/td>\n<td>\u7248\u672c \u72b6\u6001\u7801 \u63cf\u8ff0<\/td>\n<td>HTTP\/1.1 200 OK<\/td>\n<\/tr>\n<tr>\n<td>Header<\/td>\n<td>\u952e: \u503c\\\\r\\\\n<\/td>\n<td>Content-Type: text\/html<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a\u884c<\/td>\n<td>\\\\r\\\\n&#xff08;\u5355\u72ec\u4e00\u884c&#xff09;<\/td>\n<td>\u5206\u9694 Header \u548c Body<\/td>\n<\/tr>\n<tr>\n<td>Body<\/td>\n<td>\u4efb\u610f\u5185\u5bb9<\/td>\n<td>HTML \/ JSON \/ \u56fe\u7247\u4e8c\u8fdb\u5236<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u65e0\u8bba\u591a\u590d\u6742\u7684 Web \u5e94\u7528\u2014\u2014\u65e0\u8bba\u662f Google \u7684\u641c\u7d22\u7ed3\u679c\u9875\u8fd8\u662f\u4f60\u7684\u535a\u5ba2\u540e\u53f0\u2014\u2014\u5e95\u5c42 HTTP \u901a\u4fe1\u90fd\u662f\u8fd9\u4e94\u4e2a\u5143\u7d20\u7684\u6392\u5217\u7ec4\u5408\u3002\u638c\u63e1\u4e86\u5b83\u4eec&#xff0c;\u4f60\u5c31\u62ff\u5230\u4e86\u7406\u89e3\u6574\u4e2a Web \u4e16\u754c\u7684\u94a5\u5319\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183617-6a63b0a1b357d.png\" alt=\"QQ20260611-235227\" \/><\/p>\n<p>\u6700\u540e&#xff0c;\u8ba9\u6211\u4eec\u8df3\u51fa\u5177\u4f53\u7684\u6280\u672f\u7ec6\u8282&#xff0c;\u4ece\u66f4\u9ad8\u7684\u89c6\u89d2\u5ba1\u89c6\u4e00\u4e0b HTTP\u3002HTTP \u534f\u8bae\u8bde\u751f\u4e8e 1991 \u5e74\u2014\u2014\u90a3\u65f6\u4e92\u8054\u7f51\u8fd8\u662f\u5b66\u672f\u754c\u7684\u5c0f\u5708\u5b50&#xff0c;\u7f51\u9875\u53ea\u6709\u7eaf\u6587\u672c\u3002\u4e09\u5341\u591a\u5e74\u8fc7\u53bb&#xff0c;\u5b83\u627f\u8f7d\u4e86\u89c6\u9891\u6d41\u3001\u5b9e\u65f6\u901a\u4fe1\u3001\u6587\u4ef6\u4e0a\u4f20\u3001API \u8c03\u7528\u3001\u5fae\u670d\u52a1\u95f4\u901a\u4fe1&#xff0c;\u751a\u81f3\u7269\u8054\u7f51\u8bbe\u5907\u7684\u6570\u636e\u4e0a\u62a5\u3002\u4e00\u4e2a 1991 \u5e74\u8bbe\u8ba1\u7684\u534f\u8bae\u5982\u4f55\u80fd\u652f\u6491 2026 \u5e74\u7684\u4e92\u8054\u7f51&#xff1f;\u7b54\u6848\u5728\u4e8e HTTP \u7684\u7248\u672c\u517c\u5bb9\u6027\u7b56\u7565&#xff1a;HTTP\/1.1 \u670d\u52a1\u5668\u53ef\u4ee5\u7406\u89e3 HTTP\/1.0 \u7684\u8bf7\u6c42&#xff08;\u5ffd\u7565\u4e0d\u8ba4\u8bc6\u7684 Header&#xff09;&#xff0c;HTTP\/2 \u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7 ALPN \u534f\u5546\u964d\u7ea7\u5230 HTTP\/1.1&#xff0c;HTTP\/3 \u53ef\u4ee5\u901a\u8fc7 HTTP Alternative Services \u544a\u8bc9\u6d4f\u89c8\u5668&#034;\u4e0b\u6b21\u7528 QUIC \u8fde\u6211&#034;\u3002\u6bcf\u4e00\u4e2a\u65b0\u7248\u672c\u90fd\u4e0d\u662f&#034;\u66ff\u6362&#034;\u65e7\u7248\u672c&#xff0c;\u800c\u662f&#034;\u6269\u5c55&#034;\u2014\u2014\u8001\u65e7\u5ba2\u6237\u7aef\u53ef\u4ee5\u7ee7\u7eed\u7528 HTTP\/1.0 \u8bbf\u95ee\u540c\u4e00\u4e2a\u670d\u52a1\u5668&#xff0c;\u65b0\u5ba2\u6237\u7aef\u81ea\u52a8\u5347\u7ea7\u5230 HTTP\/2 \u6216 HTTP\/3\u3002\u8fd9\u79cd\u6e10\u8fdb\u5f0f\u5347\u7ea7\u7b56\u7565\u662f\u6240\u6709\u957f\u5bff\u534f\u8bae&#xff08;HTTP\u3001TCP\/IP\u3001TLS&#xff09;\u7684\u5171\u540c\u7279\u5f81&#xff1a;\u4e0d\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5b8c\u7f8e\u7684\u534f\u8bae\u7136\u540e\u5f3a\u8feb\u6240\u6709\u4eba\u5347\u7ea7&#xff0c;\u800c\u662f\u8bbe\u8ba1\u4e00\u4e2a\u80fd\u5bb9\u5fcd\u4e0d\u5b8c\u7f8e\u7684\u534f\u8bae\u5e76\u5141\u8bb8\u6e10\u8fdb\u5f0f\u8fdb\u5316\u3002<\/p>\n<h4>\u52a8\u624b\u8bd5\u8bd5<\/h4>\n<li>\u6539\u9020 HTTP \u670d\u52a1\u5668&#xff0c;\u652f\u6301 301 \u91cd\u5b9a\u5411\u2014\u2014\u8bbf\u95ee \/old \u65f6\u81ea\u52a8\u8df3\u8f6c\u5230 \/new\u3002\u89c2\u5bdf\u6d4f\u89c8\u5668\u5730\u5740\u680f\u7684\u53d8\u5316\u3002<\/li>\n<li>\u7ed9\u670d\u52a1\u5668\u589e\u52a0 Cookie \u652f\u6301\u2014\u2014\u7b2c\u4e00\u6b21\u8bbf\u95ee\u65f6 Set-Cookie: visit_count&#061;1&#xff0c;\u540e\u7eed\u6bcf\u6b21\u8bf7\u6c42\u4ece\u8bf7\u6c42 Header \u7684 Cookie \u4e2d\u8bfb\u53d6\u51fa visit_count \u5e76\u9012\u589e\u8fd4\u56de&#xff08;\u63d0\u793a&#xff1a;\u7528 std::map \u7ef4\u62a4 IP\u2192\u8bbf\u95ee\u6b21\u6570\u7684\u6620\u5c04&#xff0c;sprintf \u6784\u9020 Set-Cookie \u5934&#xff09;\u3002<\/li>\n<li>\u7528 nc&#xff08;netcat&#xff09;\u624b\u5de5\u6784\u9020\u4e00\u6761 HTTP \u8bf7\u6c42\u53d1\u7ed9\u4f60\u7684\u670d\u52a1\u5668&#xff1a;printf &#034;GET \/ HTTP\/1.0\\\\r\\\\n\\\\r\\\\n&#034; | nc 127.0.0.1 9090&#xff0c;\u89c2\u5bdf\u8fd4\u56de\u7684\u539f\u59cb HTTP \u54cd\u5e94\u3002<\/li>\n<li>\u7ed9\u4f60\u7684\u670d\u52a1\u5668\u589e\u52a0 304 \u7f13\u5b58\u652f\u6301\u2014\u2014\u8bfb\u53d6\u6587\u4ef6\u7684\u4fee\u6539\u65f6\u95f4&#xff08;stat \u7cfb\u7edf\u8c03\u7528&#xff09;&#xff0c;\u5982\u679c\u6d4f\u89c8\u5668\u53d1\u6765\u7684 If-Modified-Since \u65f6\u95f4\u665a\u4e8e\u6216\u7b49\u4e8e\u6587\u4ef6\u4fee\u6539\u65f6\u95f4&#xff0c;\u8fd4\u56de 304 Not Modified \u800c\u4e0d\u53d1\u9001 Body\u3002<\/li>\n<p>\u9884\u544a&#xff1a; \u6211\u4eec\u5c06\u8fdb\u5165 TCP \u4f20\u8f93\u63a7\u5236\u534f\u8bae\u7684\u53ef\u9760\u4f20\u8f93\u673a\u5236\u2014\u2014\u4e09\u6b21\u63e1\u624b\u56db\u6b21\u6325\u624b\u7684\u72b6\u6001\u673a\u3001\u786e\u8ba4\u5e94\u7b54\u3001\u8d85\u65f6\u91cd\u4f20\u3001\u6ed1\u52a8\u7a97\u53e3\u4e0e\u62e5\u585e\u63a7\u5236\u3002\u7406\u89e3 TCP \u624d\u80fd\u7406\u89e3 HTTP \u4e3a\u4ec0\u4e48\u6709\u65f6\u5019\u5feb\u6709\u65f6\u5019\u6162\u3002<\/p>\n<h3>\u9644\u5f55&#xff1a;HTTP \u7248\u672c\u6f14\u8fdb\u7b80\u53f2<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183618-6a63b0a203db1.png\" alt=\"QQ20260611-235407\" \/><\/p>\n<p>\u7406\u89e3 HTTP \u7684\u6f14\u8fdb\u5386\u53f2&#xff0c;\u80fd\u5e2e\u4f60\u7406\u89e3\u4e3a\u4ec0\u4e48\u4eca\u5929\u7684 HTTP \u8fd9\u4e48\u590d\u6742\u3002<\/p>\n<table>\n<tr>\u7248\u672c\u5e74\u4efd\u6838\u5fc3\u7279\u6027\u81f4\u547d\u5c40\u9650\u5e95\u5c42\u4f20\u8f93<\/tr>\n<tbody>\n<tr>\n<td>0.9<\/td>\n<td>1991<\/td>\n<td>\u4ec5 GET&#xff0c;\u4ec5 HTML&#xff0c;\u65e0 Header<\/td>\n<td>\u53ea\u80fd\u8bf7\u6c42\u4e00\u4e2a HTML \u6587\u4ef6<\/td>\n<td>TCP<\/td>\n<\/tr>\n<tr>\n<td>1.0<\/td>\n<td>1996<\/td>\n<td>POST\/HEAD&#xff0c;Header&#xff0c;\u72b6\u6001\u7801&#xff0c;\u7f13\u5b58<\/td>\n<td>\u6bcf\u4e2a\u8bf7\u6c42\u4e00\u4e2a\u65b0 TCP \u8fde\u63a5<\/td>\n<td>TCP<\/td>\n<\/tr>\n<tr>\n<td>1.1<\/td>\n<td>1999<\/td>\n<td>\u6301\u4e45\u8fde\u63a5&#xff0c;\u7ba1\u9053\u5316&#xff0c;Host \u5934&#xff08;\u865a\u62df\u4e3b\u673a&#xff09;&#xff0c;\u5206\u5757\u4f20\u8f93\u7f16\u7801<\/td>\n<td>\u961f\u5934\u963b\u585e\u2014\u2014\u4e00\u4e2a\u8bf7\u6c42\u5361\u4f4f&#xff0c;\u540e\u7eed\u5168\u90e8\u6392\u961f<\/td>\n<td>TCP<\/td>\n<\/tr>\n<tr>\n<td>2.0<\/td>\n<td>2015<\/td>\n<td>\u591a\u8def\u590d\u7528&#xff0c;\u4e8c\u8fdb\u5236\u5e27&#xff0c;\u5934\u90e8\u538b\u7f29&#xff08;HPACK&#xff09;&#xff0c;\u670d\u52a1\u5668\u63a8\u9001<\/td>\n<td>TCP \u5c42\u7684\u4e22\u5305\u5bfc\u81f4\u6240\u6709\u6d41\u963b\u585e<\/td>\n<td>TCP<\/td>\n<\/tr>\n<tr>\n<td>3.0<\/td>\n<td>2022<\/td>\n<td>\u57fa\u4e8e QUIC&#xff08;UDP&#xff09;&#xff0c;0-RTT \u8fde\u63a5\u5efa\u7acb&#xff0c;\u6d88\u9664 TCP \u961f\u5934\u963b\u585e&#xff0c;\u8fde\u63a5\u8fc1\u79fb&#xff08;WiFi\u21924G \u4e0d\u65ad\u5f00&#xff09;<\/td>\n<td>\u90e8\u7f72\u590d\u6742\u5ea6\u9ad8&#xff08;UDP \u88ab\u90e8\u5206\u7f51\u7edc\u5c01\u5835&#xff0c;CPU \u5f00\u9500\u6bd4 TCP \u9ad8&#xff09;<\/td>\n<td>UDP&#xff08;QUIC&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>HTTP\/3.0 \u4ece TCP \u8f6c\u5411 UDP &#043; QUIC\u2014\u2014\u8fd9\u6b63\u662f 23 \u7bc7 UDP \u534f\u8bae\u8be6\u89e3\u4e2d\u6240\u8bf4\u7684&#034;\u5728 UDP \u4e4b\u4e0a\u81ea\u5efa\u53ef\u9760\u6027&#034;\u3002\u4e09\u5341\u5e74\u65f6\u95f4&#xff0c;\u5e95\u5c42\u4f20\u8f93\u4ece TCP \u515c\u4e86\u4e00\u5708\u56de\u5230 UDP&#xff0c;\u4f46\u4e0a\u5c42\u7684\u53ef\u9760\u6027\u88ab QUIC \u91cd\u65b0\u5b9e\u73b0\u4e86\u4e00\u904d\u2014\u2014\u53ea\u662f\u8fd9\u6b21\u6bd4 TCP \u505a\u5f97\u66f4\u597d\u3002<\/p>\n<p>HTTP \u7248\u672c\u7684\u6f14\u8fdb\u53f2\u5bf9\u6211\u4eec\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u542f\u793a&#xff1a;\u534f\u8bae\u8bbe\u8ba1\u662f\u4e00\u573a\u6ca1\u6709\u7ec8\u70b9\u7684\u6743\u8861\u3002 HTTP\/1.0 \u7684\u77ed\u8fde\u63a5\u7b80\u5355\u4f46\u6548\u7387\u4f4e&#xff1b;HTTP\/1.1 \u7684 keep-alive \u63d0\u9ad8\u4e86\u6548\u7387\u4f46\u5f15\u5165\u4e86\u961f\u5934\u963b\u585e&#xff1b;HTTP\/2 \u7684\u591a\u8def\u590d\u7528\u89e3\u51b3\u4e86\u961f\u5934\u963b\u585e\u5374\u53d7\u9650\u4e8e TCP \u5c42\u7684\u4e22\u5305\u91cd\u4f20&#xff1b;HTTP\/3 \u8f6c\u5411 QUIC&#xff08;\u57fa\u4e8e UDP&#xff09;\u5f7b\u5e95\u89e3\u51b3\u4e86 TCP \u961f\u5934\u963b\u585e\u4f46\u53c8\u9762\u4e34 UDP \u88ab\u90e8\u5206\u7f51\u7edc\u5c01\u5835\u7684\u90e8\u7f72\u96be\u9898\u3002\u6bcf\u4e00\u6b65\u90fd\u662f&#034;\u7528\u4e00\u4e2a\u65b0\u95ee\u9898\u6362\u4e00\u4e2a\u8001\u95ee\u9898&#034;\u3002\u77e5\u9053\u6bcf\u4e2a\u7248\u672c\u89e3\u51b3\u4e86\u4ec0\u4e48\u3001\u727a\u7272\u4e86\u4ec0\u4e48&#xff0c;\u6bd4\u8bb0\u4f4f\u6bcf\u4e2a\u7248\u672c\u7684\u540d\u5b57\u91cd\u8981\u5f97\u591a\u2014\u2014\u56e0\u4e3a\u4f60\u5c06\u6765\u53c2\u4e0e\u8bbe\u8ba1\u7684\u4efb\u4f55\u6280\u672f\u65b9\u6848&#xff0c;\u672c\u8d28\u4e0a\u4e5f\u662f\u5728\u505a\u540c\u6837\u7684\u6743\u8861\u3002<\/p>\n<h3>\u5c3e\u58f0<\/h3>\n<p>\u672c\u7ae0\u8bb2\u89e3\u5c31\u5230\u6b64\u7ed3\u675f\u4e86&#xff0c;\u82e5\u6709\u7eb0\u6f0f\u6216\u4e0d\u8db3\u4e4b\u5904\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u6216\u8005\u79c1\u4fe1&#xff0c;\u540c\u65f6\u4e5f\u6b22\u8fce\u5404\u4f4d\u4e00\u8d77\u63a2\u8ba8\u5b66\u4e60\u3002\u611f\u8c22\u60a8\u7684\u89c2\u770b&#xff01;<\/p>\n<p>\u66f4\u591a\u5185\u5bb9\u53ef\u89c1\u4e3b\u9875<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u541b\u6d4f\u89c8\u524d\u8a00\u4e00\u3001HTTP \u534f\u8bae\u6982\u8ff01.1 \u8ba4\u8bc6 URL1.2 urlencode \u4e0e urldecode\u4e8c\u3001HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u683c\u5f0f2.1 \u8bf7\u6c42\u683c\u5f0f2.2 \u54cd\u5e94\u683c\u5f0f2.3 \u624b\u5de5\u9a8c\u8bc1&#xff1a;\u7528 netcat \u53d1\u9001 HTTP \u8bf7\u6c42\u4e09\u3001HTTP \u65b9\u6cd53.1 GET \u4e0e POST \u7684\u6838\u5fc3\u533a\u522b3.2 \u8868\u5355\u63d0\u4ea4&#xff1a;GET \u8fd8\u662f POST\u56db\u3001HTTP \u72b6\u6001\u7801\u4e0e\u91cd\u5b9a\u54114.1 \u72b6\u6001\u7801\u901f\u67e54.2 \u91cd\u5b9a\u5411\u7684\u5e95\u5c42\u673a\u5236\u4e94\u3001HTTP \u5e38\u89c1 Header5.1 \u6838\u5fc3 Header \u4e00\u89c8<\/p>\n","protected":false},"author":2,"featured_media":81473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[151,58,43,78],"topic":[],"class_list":["post-81488","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-http","tag-linux","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \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\/81488.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u8bf7\u541b\u6d4f\u89c8\u524d\u8a00\u4e00\u3001HTTP \u534f\u8bae\u6982\u8ff01.1 \u8ba4\u8bc6 URL1.2 urlencode \u4e0e urldecode\u4e8c\u3001HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u683c\u5f0f2.1 \u8bf7\u6c42\u683c\u5f0f2.2 \u54cd\u5e94\u683c\u5f0f2.3 \u624b\u5de5\u9a8c\u8bc1&#xff1a;\u7528 netcat \u53d1\u9001 HTTP \u8bf7\u6c42\u4e09\u3001HTTP \u65b9\u6cd53.1 GET \u4e0e POST \u7684\u6838\u5fc3\u533a\u522b3.2 \u8868\u5355\u63d0\u4ea4&#xff1a;GET \u8fd8\u662f POST\u56db\u3001HTTP \u72b6\u6001\u7801\u4e0e\u91cd\u5b9a\u54114.1 \u72b6\u6001\u7801\u901f\u67e54.2 \u91cd\u5b9a\u5411\u7684\u5e95\u5c42\u673a\u5236\u4e94\u3001HTTP \u5e38\u89c1 Header5.1 \u6838\u5fc3 Header \u4e00\u89c8\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/81488.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-24T18:36:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183605-6a63b09544017.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=\"14 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81488.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/81488.html\",\"name\":\"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-24T18:36:20+00:00\",\"dateModified\":\"2026-07-24T18:36:20+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/81488.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/81488.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81488.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668\"}]},{\"@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":"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \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\/81488.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u8bf7\u541b\u6d4f\u89c8\u524d\u8a00\u4e00\u3001HTTP \u534f\u8bae\u6982\u8ff01.1 \u8ba4\u8bc6 URL1.2 urlencode \u4e0e urldecode\u4e8c\u3001HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u683c\u5f0f2.1 \u8bf7\u6c42\u683c\u5f0f2.2 \u54cd\u5e94\u683c\u5f0f2.3 \u624b\u5de5\u9a8c\u8bc1&#xff1a;\u7528 netcat \u53d1\u9001 HTTP \u8bf7\u6c42\u4e09\u3001HTTP \u65b9\u6cd53.1 GET \u4e0e POST \u7684\u6838\u5fc3\u533a\u522b3.2 \u8868\u5355\u63d0\u4ea4&#xff1a;GET \u8fd8\u662f POST\u56db\u3001HTTP \u72b6\u6001\u7801\u4e0e\u91cd\u5b9a\u54114.1 \u72b6\u6001\u7801\u901f\u67e54.2 \u91cd\u5b9a\u5411\u7684\u5e95\u5c42\u673a\u5236\u4e94\u3001HTTP \u5e38\u89c1 Header5.1 \u6838\u5fc3 Header \u4e00\u89c8","og_url":"https:\/\/www.wsisp.com\/helps\/81488.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-24T18:36:20+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724183605-6a63b09544017.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"14 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/81488.html","url":"https:\/\/www.wsisp.com\/helps\/81488.html","name":"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-24T18:36:20+00:00","dateModified":"2026-07-24T18:36:20+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/81488.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/81488.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/81488.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u4e4b\u65c5\u3011HTTP \u534f\u8bae\u89e3\u6790\uff1a\u4ece\u8bf7\u6c42\u683c\u5f0f\u5230\u6784\u5efa Web \u670d\u52a1\u5668"}]},{"@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\/81488","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=81488"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81488\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/81473"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=81488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=81488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=81488"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=81488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}