{"id":11259,"date":"2025-04-18T18:33:21","date_gmt":"2025-04-18T10:33:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/11259.html"},"modified":"2025-04-18T18:33:21","modified_gmt":"2025-04-18T10:33:21","slug":"%e3%80%90c%e3%80%91httplib%ef%bc%9a%e8%bd%bb%e9%87%8f%e7%ba%a7%e7%9a%84-http-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%92%8c%e5%ae%a2%e6%88%b7%e7%ab%af","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/11259.html","title":{"rendered":"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef"},"content":{"rendered":"<p>\u672c\u6559\u7a0b\u91c7\u7528\u6e10\u8fdb\u5f0f\u8bb2\u89e3\u65b9\u5f0f&#xff0c;\u9002\u7528\u4e8e MinGW \u73af\u5883\u3002\u6211\u4eec\u5c06\u4ece httplib \u7684\u57fa\u672c\u6982\u5ff5\u5165\u624b&#xff0c;\u901a\u8fc7\u4e00\u4e2a\u5c0f\u578b Demo \u5c55\u793a\u5176\u6838\u5fc3\u7528\u6cd5&#xff0c;\u6700\u540e\u6df1\u5165\u63a2\u8ba8\u9ad8\u7ea7\u529f\u80fd\u4e0e\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002<\/p>\n<hr \/>\n<h3>1. \u7b80\u4ecb<\/h3>\n<h4>1.1 httplib \u57fa\u672c\u6982\u5ff5<\/h4>\n<p>httplib \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 C&#043;&#043; HTTP \u5e93&#xff0c;\u8bbe\u8ba1\u521d\u8877\u662f\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u548c\u8d44\u6e90\u53d7\u9650\u73af\u5883\u63d0\u4f9b\u7b80\u6d01\u9ad8\u6548\u7684 HTTP \u652f\u6301\u3002\u5b83\u662f\u4e00\u4e2a\u5355\u5934\u6587\u4ef6\u5e93&#xff08;httplib.h&#xff09;&#xff0c;\u65e0\u9700\u5916\u90e8\u4f9d\u8d56&#xff0c;\u652f\u6301\u521b\u5efa HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef&#xff0c;\u5e76\u517c\u5bb9 HTTP\/1.1 \u534f\u8bae\u3002httplib \u7684\u4e3b\u8981\u7279\u70b9\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u65e0\u5916\u90e8\u4f9d\u8d56&#xff1a;\u53ea\u9700\u5305\u542b\u5934\u6587\u4ef6\u5373\u53ef\u4f7f\u7528&#xff0c;\u65e0\u9700\u989d\u5916\u7684\u5e93\u6587\u4ef6\u3002<\/li>\n<li>\u8de8\u5e73\u53f0&#xff1a;\u652f\u6301 Windows\u3001Linux \u548c macOS \u7b49\u64cd\u4f5c\u7cfb\u7edf\u3002<\/li>\n<li>\u7b80\u5355\u6613\u7528&#xff1a;\u63d0\u4f9b\u76f4\u89c2\u7684 API&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u5feb\u901f\u5b9e\u73b0 HTTP \u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u5904\u7406\u3002<\/li>\n<li>\u652f\u6301 SSL\/TLS&#xff1a;\u901a\u8fc7\u96c6\u6210 OpenSSL&#xff0c;\u53ef\u4ee5\u542f\u7528 HTTPS \u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u5728 MinGW \u73af\u5883\u4e0b&#xff0c;\u7f16\u8bd1\u65f6\u53ef\u80fd\u9700\u8981\u94fe\u63a5 ws2_32 \u5e93&#xff08;\u89c6\u5177\u4f53\u5b9e\u73b0\u800c\u5b9a&#xff09;&#xff0c;\u65b9\u6cd5\u662f\u5728\u7f16\u8bd1\u547d\u4ee4\u4e2d\u6dfb\u52a0 -lws2_32 \u53c2\u6570\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u9759\u6001\u94fe\u63a5 MinGW \u5e93\u6765\u907f\u514d\u8fd0\u884c\u65f6\u4f9d\u8d56\u52a8\u6001\u5e93\u3002\u5177\u4f53\u7684\u7f16\u8bd1\u547d\u4ee4\u5982\u4e0b&#xff1a;<\/p>\n<p>g&#043;&#043; -o main.exe main.cpp -lws2_32 -static-libgcc -static-libstdc&#043;&#043; -Wl,-Bstatic -lstdc&#043;&#043; -lpthread<\/p>\n<ul>\n<li>static-libgcc&#xff1a;\u9759\u6001\u94fe\u63a5 GCC \u8fd0\u884c\u65f6\u5e93\u3002<\/li>\n<li>static-libstdc&#043;&#043;&#xff1a;\u9759\u6001\u94fe\u63a5 C&#043;&#043; \u6807\u51c6\u5e93\u3002<\/li>\n<li>Wl,-Bstatic -lstdc&#043;&#043; -lpthread&#xff1a;\u786e\u4fdd\u6807\u51c6\u5e93\u548c\u7ebf\u7a0b\u5e93\u4e5f\u4ee5\u9759\u6001\u65b9\u5f0f\u94fe\u63a5\u3002<\/li>\n<\/ul>\n<h4>1.2 \u83b7\u53d6 httplib<\/h4>\n<p>\u7531\u4e8e httplib \u662f\u5934\u6587\u4ef6\u5e93&#xff0c;\u5b89\u88c5\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u4ece\u5176\u5b98\u65b9 GitHub \u4ed3\u5e93&#xff08;https:\/\/github.com\/yhirose\/cpp-httplib&#xff09;\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684 httplib.h&#xff0c;\u7136\u540e\u5c06\u5176\u653e\u5165\u9879\u76ee\u76ee\u5f55&#xff0c;\u5e76\u5728\u4ee3\u7801\u4e2d\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5305\u542b&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;httplib.h&#034;<\/span><\/span><\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c06\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684 Demo \u5c55\u793a httplib \u7684\u6838\u5fc3\u7528\u6cd5\u3002<\/p>\n<hr \/>\n<h3>2. \u5feb\u901f\u5165\u95e8&#xff1a;\u4e00\u4e2a\u5c0f\u578b Demo<\/h3>\n<p>\u4e3a\u4e86\u8ba9\u4f60\u5feb\u901f\u4e0a\u624b&#xff0c;\u6211\u4eec\u5c06\u7f16\u5199\u4e00\u4e2a HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684\u793a\u4f8b\u3002\u670d\u52a1\u5668\u76d1\u542c\u672c\u5730 8080 \u7aef\u53e3\u5e76\u8fd4\u56de\u7b80\u5355\u6d88\u606f&#xff0c;\u5ba2\u6237\u7aef\u5219\u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\u5e76\u6253\u5370\u54cd\u5e94\u3002<\/p>\n<h4>2.1 HTTP \u670d\u52a1\u5668 Demo<\/h4>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 HTTP \u670d\u52a1\u5668\u5b9e\u73b0&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;httplib.h&#034;<\/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;iostream&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 punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u521b\u5efa HTTP \u670d\u52a1\u5668<\/span><br \/>\n    httplib<span class=\"token operator\">::<\/span>Server svr<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5b9a\u4e49\u6839\u8def\u5f84\u7684 GET \u8bf7\u6c42\u5904\u7406<\/span><br \/>\n    svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello, World!&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u76d1\u542c localhost:8080<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Server started at http:\/\/localhost:8080&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">listen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;localhost&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">8080<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <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>\u7f16\u8bd1\u547d\u4ee4&#xff1a;<\/p>\n<p>g&#043;&#043; -o server server.cpp -lws2_32<\/p>\n<p>\u4ee3\u7801\u8bf4\u660e&#xff1a;<\/p>\n<li>httplib::Server \u521b\u5efa\u670d\u52a1\u5668\u5b9e\u4f8b\u3002<\/li>\n<li>svr.Get \u5b9a\u4e49\u4e86\u5bf9 \/ \u8def\u5f84\u7684 GET \u8bf7\u6c42\u5904\u7406&#xff0c;\u8fd4\u56de\u7eaf\u6587\u672c \u201cHello, World!\u201d\u3002<\/li>\n<li>svr.listen \u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u76d1\u542c\u6307\u5b9a\u5730\u5740\u548c\u7aef\u53e3\u3002<\/li>\n<h4>2.2 HTTP \u5ba2\u6237\u7aef Demo<\/h4>\n<p>\u4ee5\u4e0b\u662f\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef\u4ee3\u7801&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;httplib.h&#034;<\/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;iostream&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 punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u521b\u5efa HTTP \u5ba2\u6237\u7aef&#xff0c;\u8fde\u63a5 localhost:8080<\/span><br \/>\n    httplib<span class=\"token operator\">::<\/span>Client <span class=\"token function\">cli<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;localhost&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">8080<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u53d1\u9001 GET \u8bf7\u6c42<\/span><br \/>\n    <span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u68c0\u67e5\u5e76\u8f93\u51fa\u54cd\u5e94<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>res <span class=\"token operator\">&amp;&amp;<\/span> res<span class=\"token operator\">-&gt;<\/span>status <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Response: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> res<span class=\"token operator\">-&gt;<\/span>body <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;Request failed&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <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>\u7f16\u8bd1\u547d\u4ee4&#xff1a;<\/p>\n<p>g&#043;&#043; -o client client.cpp -lws2_32<\/p>\n<p>\u4ee3\u7801\u8bf4\u660e&#xff1a;<\/p>\n<li>httplib::Client \u521b\u5efa\u5ba2\u6237\u7aef\u5b9e\u4f8b&#xff0c;\u6307\u5b9a\u670d\u52a1\u5668\u5730\u5740\u548c\u7aef\u53e3\u3002<\/li>\n<li>cli.Get \u53d1\u9001 GET \u8bf7\u6c42\u5230 \/ \u8def\u5f84\u3002<\/li>\n<li>\u68c0\u67e5\u54cd\u5e94\u5bf9\u8c61 res&#xff0c;\u786e\u4fdd\u8bf7\u6c42\u6210\u529f&#xff08;\u72b6\u6001\u7801 200&#xff09;&#xff0c;\u5e76\u8f93\u51fa\u54cd\u5e94\u6b63\u6587\u3002<\/li>\n<h4>2.3 \u8fd0\u884c Demo<\/h4>\n<li>\n<p>\u6253\u5f00\u4e00\u4e2a\u7ec8\u7aef&#xff0c;\u8fd0\u884c\u670d\u52a1\u5668&#xff1a;<\/p>\n<p> .\/server<\/p>\n<p>\u4f60\u5c06\u770b\u5230\u63d0\u793a \u201cServer started at http:\/\/localhost:8080\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u6253\u5f00\u53e6\u4e00\u4e2a\u7ec8\u7aef&#xff0c;\u8fd0\u884c\u5ba2\u6237\u7aef&#xff1a;<\/p>\n<p> .\/client<\/p>\n<p>\u5ba2\u6237\u7aef\u5c06\u8f93\u51fa \u201cResponse: Hello, World!\u201d\u3002<\/p>\n<\/li>\n<p>\u901a\u8fc7\u8fd9\u4e2a Demo&#xff0c;\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86 httplib \u521b\u5efa\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684\u57fa\u672c\u6d41\u7a0b\u3002\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5176\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<hr \/>\n<h3>3. \u6df1\u5165\u63a2\u8ba8&#xff1a;\u9ad8\u7ea7\u529f\u80fd\u4e0e\u5b9e\u9645\u5e94\u7528<\/h3>\n<p>\u5728\u5feb\u901f\u5165\u95e8\u4e2d&#xff0c;\u6211\u4eec\u4e86\u89e3\u4e86 httplib \u7684\u57fa\u7840\u7528\u6cd5\u3002\u73b0\u5728&#xff0c;\u6211\u4eec\u5c06\u63a2\u7d22\u5176\u9ad8\u7ea7\u529f\u80fd&#xff0c;\u5e76\u5c55\u793a\u5982\u4f55\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u5e94\u7528\u8fd9\u4e9b\u7279\u6027\u3002<\/p>\n<h4>3.1 HTTP \u670d\u52a1\u5668\u9ad8\u7ea7\u529f\u80fd<\/h4>\n<h5>3.1.1 \u8def\u7531\u548c\u53c2\u6570\u5316\u8def\u5f84<\/h5>\n<p>httplib \u652f\u6301\u591a\u79cd HTTP \u65b9\u6cd5&#xff08;GET\u3001POST\u3001PUT\u3001DELETE \u7b49&#xff09;&#xff0c;\u5e76\u5141\u8bb8\u4e3a\u4e0d\u540c\u8def\u5f84\u8bbe\u7f6e\u5904\u7406\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b&#xff0c;\u5c55\u793a\u5982\u4f55\u5904\u7406\u53c2\u6570\u5316\u8def\u5f84\u548c POST \u8bf7\u6c42&#xff1a;<\/p>\n<p>svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/user\/:id&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">auto<\/span> id <span class=\"token operator\">&#061;<\/span> req<span class=\"token punctuation\">.<\/span>path_params<span class=\"token punctuation\">.<\/span><span class=\"token function\">at<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;id&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6\u8def\u5f84\u53c2\u6570<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;User ID: &#034;<\/span> <span class=\"token operator\">&#043;<\/span> id<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/submit&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">auto<\/span> data <span class=\"token operator\">&#061;<\/span> req<span class=\"token punctuation\">.<\/span>body<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6 POST \u6570\u636e<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Received: &#034;<\/span> <span class=\"token operator\">&#043;<\/span> data<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8bbf\u95ee \/user\/123 \u5c06\u8fd4\u56de \u201cUser ID: 123\u201d\u3002<\/p>\n<h5>3.1.2 \u9759\u6001\u6587\u4ef6\u670d\u52a1<\/h5>\n<p>httplib \u53ef\u4ee5\u5c06\u672c\u5730\u76ee\u5f55\u6620\u5c04\u4e3a\u9759\u6001\u6587\u4ef6\u670d\u52a1\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_mount_point<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;.\/www&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5047\u8bbe .\/www \u76ee\u5f55\u4e0b\u6709 index.html&#xff0c;\u8bbf\u95ee http:\/\/localhost:8080\/index.html \u5c06\u8fd4\u56de\u8be5\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<h5>3.1.3 SSL\/TLS \u652f\u6301<\/h5>\n<p>\u8981\u542f\u7528 HTTPS&#xff0c;\u9700\u8981\u4f7f\u7528 httplib::SSLServer \u5e76\u63d0\u4f9b\u8bc1\u4e66\u548c\u79c1\u94a5&#xff1a;<\/p>\n<p>httplib<span class=\"token operator\">::<\/span>SSLServer <span class=\"token function\">svr<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;cert.pem&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;key.pem&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nsvr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello, HTTPS!&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nsvr<span class=\"token punctuation\">.<\/span><span class=\"token function\">listen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;localhost&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">443<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;\u7f16\u8bd1\u65f6\u9700\u94fe\u63a5 OpenSSL \u5e93&#xff08;-lssl -lcrypto&#xff09;&#xff0c;\u5e76\u786e\u4fdd MinGW \u73af\u5883\u652f\u6301 OpenSSL\u3002<\/p>\n<h4>3.2 HTTP \u5ba2\u6237\u7aef\u9ad8\u7ea7\u529f\u80fd<\/h4>\n<h5>3.2.1 \u53d1\u9001\u591a\u79cd\u8bf7\u6c42<\/h5>\n<p>\u5ba2\u6237\u7aef\u652f\u6301 GET\u3001POST\u3001PUT\u3001DELETE \u7b49\u8bf7\u6c42\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ POST \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/submit&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;data&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ PUT \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Put<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/update&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;new data&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ DELETE \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Delete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/delete&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>3.2.2 \u8bbe\u7f6e\u8bf7\u6c42\u5934<\/h5>\n<p>\u53ef\u4ee5\u901a\u8fc7 httplib::Headers \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8bf7\u6c42\u5934&#xff1a;<\/p>\n<p>httplib<span class=\"token operator\">::<\/span>Headers headers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;Authorization&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;Bearer token&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">,<\/span> headers<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>3.2.3 HTTPS \u652f\u6301<\/h5>\n<p>\u5ba2\u6237\u7aef\u652f\u6301 HTTPS \u8bf7\u6c42&#xff1a;<\/p>\n<p>httplib<span class=\"token operator\">::<\/span>SSLClient <span class=\"token function\">cli<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;localhost&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">443<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u540c\u6837\u9700\u8981 OpenSSL \u652f\u6301\u3002<\/p>\n<h4>3.3 \u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h4>\n<h5>3.3.1 RESTful API \u670d\u52a1\u5668<\/h5>\n<p>httplib \u975e\u5e38\u9002\u5408\u6784\u5efa RESTful API\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/api\/users&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;[{\\\\&#034;id\\\\&#034;:1,\\\\&#034;name\\\\&#034;:\\\\&#034;Alice\\\\&#034;}]&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;application\/json&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>svr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/api\/users&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;User created&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>3.3.2 \u5fae\u670d\u52a1\u901a\u4fe1<\/h5>\n<p>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;httplib \u53ef\u7528\u4e8e\u670d\u52a1\u95f4\u901a\u4fe1&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u670d\u52a1 A&#xff08;\u5ba2\u6237\u7aef&#xff09;<\/span><br \/>\nhttplib<span class=\"token operator\">::<\/span>Client <span class=\"token function\">cli<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;service-b&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">8080<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> res <span class=\"token operator\">&#061;<\/span> cli<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/data&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u670d\u52a1 B&#xff08;\u670d\u52a1\u5668&#xff09;<\/span><br \/>\nsvr<span class=\"token punctuation\">.<\/span><span class=\"token function\">Get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/data&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> httplib<span class=\"token operator\">::<\/span>Request<span class=\"token operator\">&amp;<\/span> req<span class=\"token punctuation\">,<\/span> httplib<span class=\"token operator\">::<\/span>Response<span class=\"token operator\">&amp;<\/span> res<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    res<span class=\"token punctuation\">.<\/span><span class=\"token function\">set_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Data from Service B&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;text\/plain&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<hr \/>\n<h3>4. \u603b\u7ed3<\/h3>\n<p>\u901a\u8fc7\u672c\u6559\u7a0b&#xff0c;\u4f60\u5df2\u7ecf\u5168\u9762\u4e86\u89e3\u4e86 C&#043;&#043; httplib \u7684\u529f\u80fd\u3002\u4ece\u57fa\u7840\u6982\u5ff5\u5230\u5feb\u901f\u5165\u95e8 Demo&#xff0c;\u518d\u5230\u9ad8\u7ea7\u529f\u80fd\u548c\u5b9e\u9645\u5e94\u7528&#xff0c;httplib \u5c55\u793a\u4e86\u5176\u8f7b\u91cf\u3001\u7075\u6d3b\u548c\u5f3a\u5927\u7684\u7279\u6027\u3002\u5728 MinGW \u73af\u5883\u4e0b\u4f7f\u7528\u65f6&#xff0c;\u5efa\u8bae\u94fe\u63a5 ws2_32 \u5e93\u4ee5\u786e\u4fdd\u517c\u5bb9\u6027&#xff08;\u89c6\u5177\u4f53\u9700\u6c42\u800c\u5b9a&#xff09;\u3002\u5e0c\u671b\u8fd9\u7bc7\u6559\u7a0b\u80fd\u5e2e\u52a9\u4f60\u5728\u9879\u76ee\u4e2d\u9ad8\u6548\u4f7f\u7528 httplib&#xff01;<\/p>\n<hr \/>\n<p>\u4ee5\u4e0a\u662f\u4fee\u6539\u540e\u7684\u5b8c\u6574\u6559\u7a0b&#xff0c;\u53bb\u6389\u4e86 Winsock \u76f8\u5173\u5185\u5bb9\u3002\u5982\u679c\u4f60\u8fd8\u6709\u5176\u4ed6\u9700\u6c42\u6216\u6d4b\u8bd5\u4e2d\u53d1\u73b0\u65b0\u7684\u8c03\u6574\u70b9&#xff0c;\u8bf7\u968f\u65f6\u544a\u8bc9\u6211&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6559\u7a0b\u91c7\u7528\u6e10\u8fdb\u5f0f\u8bb2\u89e3\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e MinGW \u73af\u5883\u3002\u6211\u4eec\u5c06\u4ece httplib \u7684\u57fa\u672c\u6982\u5ff5\u5165\u624b\uff0c\u901a\u8fc7\u4e00\u4e2a\u5c0f\u578b Demo \u5c55\u793a\u5176\u6838\u5fc3\u7528\u6cd5\uff0c\u6700\u540e\u6df1\u5165\u63a2\u8ba8\u9ad8\u7ea7\u529f\u80fd\u4e0e\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002\u5728 MinGW \u73af\u5883\u4e0b\u4f7f\u7528 httplib \u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u7f51\u7edc\u7f16\u7a0b\u7684\u914d\u7f6e\uff0c\u6211\u4f1a\u5728\u6587\u4e2d\u9010\u6b65\u8bf4\u660e\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,151,43],"topic":[],"class_list":["post-11259","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-http","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \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\/11259.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6559\u7a0b\u91c7\u7528\u6e10\u8fdb\u5f0f\u8bb2\u89e3\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e MinGW \u73af\u5883\u3002\u6211\u4eec\u5c06\u4ece httplib \u7684\u57fa\u672c\u6982\u5ff5\u5165\u624b\uff0c\u901a\u8fc7\u4e00\u4e2a\u5c0f\u578b Demo \u5c55\u793a\u5176\u6838\u5fc3\u7528\u6cd5\uff0c\u6700\u540e\u6df1\u5165\u63a2\u8ba8\u9ad8\u7ea7\u529f\u80fd\u4e0e\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002\u5728 MinGW \u73af\u5883\u4e0b\u4f7f\u7528 httplib \u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u7f51\u7edc\u7f16\u7a0b\u7684\u914d\u7f6e\uff0c\u6211\u4f1a\u5728\u6587\u4e2d\u9010\u6b65\u8bf4\u660e\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/11259.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T10:33:21+00:00\" \/>\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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11259.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/11259.html\",\"name\":\"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T10:33:21+00:00\",\"dateModified\":\"2025-04-18T10:33:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/11259.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/11259.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11259.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\"}]},{\"@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":"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \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\/11259.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e30\u6b21\uff0c\u6536\u85cf15\u6b21\u3002\u672c\u6559\u7a0b\u91c7\u7528\u6e10\u8fdb\u5f0f\u8bb2\u89e3\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e MinGW \u73af\u5883\u3002\u6211\u4eec\u5c06\u4ece httplib \u7684\u57fa\u672c\u6982\u5ff5\u5165\u624b\uff0c\u901a\u8fc7\u4e00\u4e2a\u5c0f\u578b Demo \u5c55\u793a\u5176\u6838\u5fc3\u7528\u6cd5\uff0c\u6700\u540e\u6df1\u5165\u63a2\u8ba8\u9ad8\u7ea7\u529f\u80fd\u4e0e\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002\u5728 MinGW \u73af\u5883\u4e0b\u4f7f\u7528 httplib \u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u7f51\u7edc\u7f16\u7a0b\u7684\u914d\u7f6e\uff0c\u6211\u4f1a\u5728\u6587\u4e2d\u9010\u6b65\u8bf4\u660e\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/11259.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T10:33:21+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/11259.html","url":"https:\/\/www.wsisp.com\/helps\/11259.html","name":"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T10:33:21+00:00","dateModified":"2025-04-18T10:33:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/11259.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/11259.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/11259.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u3011httplib\uff1a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef"}]},{"@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\/11259","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=11259"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/11259\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=11259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=11259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=11259"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=11259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}