receiving data after curl_easy_perform

前端 未结 1 681
Happy的楠姐
Happy的楠姐 2021-01-21 20:46

I have the following question: how can i write data returning with http-response in char * buffer? I\'ve found several approaches:

  1. use CURLOPT_
1条回答
  •  再見小時候
    2021-01-21 21:22

    Actually CURLOPT_WRITEDATA and CURLOPT_WRITEFUNCTION can be used with any pointer type. As long as your function is compatible with that pointer type.

    For example:

        ...
        client_t *client;
        CURL *conn;
        ...
        curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, read_data);
        curl_easy_setopt(conn, CURLOPT_WRITEDATA, client);
        ...
    
    static size_t read_data(void *ptr,
                            size_t size,
                            size_t nmemb,
                            client_t *client)
    {
         memcpy(client->data, ptr, size * nmemb);
         return size * nmemb;
    }
    

    0 讨论(0)
提交回复
热议问题