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

后端 未结 22 2775
有刺的猬
有刺的猬 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:08

    Although a little bit late. You may prefer https://github.com/Taymindis/backcurl .

    It allows you to do http call on mobile c++ development. Suitable for Mobile game developement

    bcl::init(); // init when using
    
    bcl::execute([&](bcl::Request *req) {
        bcl::setOpts(req, CURLOPT_URL , "http://www.google.com",
                 CURLOPT_FOLLOWLOCATION, 1L,
                 CURLOPT_WRITEFUNCTION, &bcl::writeContentCallback,
                 CURLOPT_WRITEDATA, req->dataPtr,
                 CURLOPT_USERAGENT, "libcurl-agent/1.0",
                 CURLOPT_RANGE, "0-200000"
                );
    }, [&](bcl::Response * resp) {
        std::string ret =  std::string(resp->getBody()->c_str());
        printf("Sync === %s\n", ret.c_str());
    });
    
    
    bcl::cleanUp(); // clean up when no more using
    

提交回复
热议问题