• C++


      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;
    

      

        

  • 相关阅读:
    06-图3 六度空间
    06-图2 Saving James Bond
    06-图1 列出连通集
    05-树9 Huffman Codes
    数据结构学习笔记04树(堆 哈夫曼树 并查集)
    05-树8 File Transfer
    05-树7 堆中的路径
    十天学会单片机Day1点亮数码管(数码管、外部中断、定时器中断)
    设计模式—— 四:接口隔离原则
    设计模式—— 一:单一职责原则
  • 原文地址:https://www.cnblogs.com/darkchii/p/12236734.html
Copyright © 2020-2023  润新知