Windows 安装方法:
CMake 1.32+,生成过程会将 vcpkg 下载好,配置到系统环境变量,然后用 vcpkg 安装依赖库(github 上有列出需要的依赖库)。
Github 上的示例不全面,一开始不知道如何序列化输出 json,经过一番研究和谷歌,这里给一个示例:
#include <cpprest/http_client.h> #include <cpprest/filestream.h> //#include <boost/regex.hpp> #include <string> //#pragma comment(lib, "C:/Program Files/boost_1_72_0/bin.v2/libs/regex/build/msvc-14.2/release/address-model-64/link-static/threading-multi/libboost_regex-vc142-mt-x64-1_72.lib") #pragma comment(lib, "C:/cpprestsdk/Build_x64/Binaries/Debug/cpprest142_2_10d.lib") using namespace utility; using namespace web; using namespace web::http; using namespace web::http::client; using namespace concurrency::streams; int main() { http_client raw_client(U("https://message.bilibili.com/api/tooltip/query.list.do")); http_request request(methods::GET); request.headers().add(header_names::accept, L"application/json"); request.headers().add(header_names::user_agent, L"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"); request.headers().add(header_names::accept_encoding, L"gzip, deflate, br"); pplx::task<json::value> requestTask = raw_client.request(request).then([](http_response response) { return response.extract_json(); }); std::wcout << requestTask.get().serialize() << std::endl; return 0; }
当然也可以不用 lambda 风格,直接:
std::wcout << raw_client.request(request) .get().extract_json().get().serialize() << std::endl;
原文:https://www.cnblogs.com/darkchii/p/12236734.html