2021年4月11日星期日

curl_getinfo not returning the correct values, always returning 0

I'm trying to get the content length info and the http status code in the CURLOPT_WRITEFUNCTION callback function. I'm using curl_getinfo on the curl handle to query those fields but curl_getinfo always seems to be returning the default values.

Here is the code

      #include <stdio.h>      #include <curl/curl.h>      #include <string.h>      #include <stdlib.h>            struct url_data {          size_t size;          char* data;          CURL *curl;      };            size_t _response_header_callback(void *received_data, size_t size, size_t count, void *response_header) {              //printf("%s ", (char *)received_data);            }            size_t write_data(void *ptr, size_t size, size_t nmemb, struct url_data *data) {          size_t index = data->size;          size_t n = (size * nmemb);          char* tmp;                long responseCode = 0;          curl_easy_setopt(data->curl, CURLINFO_RESPONSE_CODE, &responseCode);          curl_off_t cl;          curl_easy_getinfo(data->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);          printf("\n whats the response Code %d %d", responseCode, cl);                      data->size += (size * nmemb);            #ifdef DEBUG          fprintf(stderr, "data at %p size=%ld nmemb=%ld\n", ptr, size, nmemb);      

没有评论:

发表评论