How do you make a HTTP request with C++?

后端 未结 22 2507
有刺的猬
有刺的猬 2020-11-22 06:25

Is there any way to easily make a HTTP request with C++? Specifically, I want to download the contents of a page (an API) and check the contents to see if it contains a 1 o

22条回答
  •  渐次进展
    2020-11-22 06:54

    You may want to check C++ REST SDK (codename "Casablanca"). http://msdn.microsoft.com/en-us/library/jj950081.aspx

    With the C++ REST SDK, you can more easily connect to HTTP servers from your C++ app.

    Usage example:

    #include 
    #include 
    
    using namespace web::http;                  // Common HTTP functionality
    using namespace web::http::client;          // HTTP client features
    
    int main(int argc, char** argv) {
        http_client client("http://httpbin.org/");
    
        http_response response;
        // ordinary `get` request
        response = client.request(methods::GET, "/get").get();
        std::cout << response.extract_string().get() << "\n";
    
        // working with json
        response = client.request(methods::GET, "/get").get();
        std::cout << "url: " << response.extract_json().get()[U("url")] << "\n";
    }
    

    The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design.

提交回复
热议问题