cpp-httplib
是一个C 11跨平台HTTP/HTTPS库。该库使用非常方便,只需要包含httplib.h
文件即可!
1. 源码主页
https://github.com/yhirose/cpp-httplib
2. 开源协议
MIT协议
3. 简单使用例子
- 服务端使用例子
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "path/to/httplib.h"
// HTTP
httplib::Server svr;
// HTTPS
httplib::SSLServer svr;
svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("0.0.0.0", 8080);
- 客户端使用例子
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "path/to/httplib.h"
// HTTP
httplib::Client cli("http://cpp-httplib-server.yhirose.repl.co");
// HTTPS
httplib::Client cli("https://cpp-httplib-server.yhirose.repl.co");
auto res = cli.Get("/hi");
res->status;
res->body;