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

后端 未结 22 2830
有刺的猬
有刺的猬 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 07:15

    There is a newer, less mature curl wrapper being developed called C++ Requests. Here's a simple GET request:

    #include 
    #include 
    
    int main(int argc, char** argv) {
        auto response = cpr::Get(cpr::Url{"http://httpbin.org/get"});
        std::cout << response.text << std::endl;
    }
    

    It supports a wide variety of HTTP verbs and curl options. There's more usage documentation here.

    Disclaimer: I'm the maintainer of this library.

提交回复
热议问题