C libcurl get output into a string

前端 未结 4 1148
粉色の甜心
粉色の甜心 2020-11-28 18:36

I want to store the result of this curl function in a variable, how can I do so?

#include 
#include 

int main(void)
{
  CU         


        
4条回答
  •  抹茶落季
    2020-11-28 19:04

    From reading the manual here: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html I think you need several calls to CURL_SETOPT, the first being the URL you want to process, the second being something like:

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, function_ptr);
    

    Where function_ptr matches this signature:

    size_t function( void *ptr, size_t size, size_t nmemb, void *stream)
    

    What happens here is you denote a callback function which libcurl will call when it has some output to write from whatever transfer you've invoked. You can get it to automatically write to a file, or pass it a pointer to a function which will handle the output itself. Using this function you should be able to assemble the various output strings into one piece and then use them in your program.

    I'm not sure what other options you may have to set / what else affects how you want your app to behave, so have a good look through that page.

提交回复
热议问题