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

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

    libCURL is a pretty good option for you. Depending on what you need to do, the tutorial should tell you what you want, specifically for the easy handle. But, basically, you could do this just to see the source of a page:

    CURL* c;
    c = curl_easy_init();
    curl_easy_setopt( c, CURL_URL, "www.google.com" );
    curl_easy_perform( c );
    curl_easy_cleanup( c );
    

    I believe this will cause the result to be printed to stdout. If you want to handle it instead -- which, I assume, you do -- you need to set the CURL_WRITEFUNCTION. All of that is covered in the curl tutorial linked above.

提交回复
热议问题