curl / Mailing Lists / curl-library / Single Mail


libcurl -data in C

From: Thomas Chen <>
Date: Sat, 7 Apr 2018 22:35:27 -0400

hello, i am trying to build a C program using libcurl  to perform same
as the curl command

when i have

# curl  -H xxx URL -d @xxx

and xxx is a big file (about 200k)

it works fine using the command line

but i am not sure how i can emulate that using libcurl and C program

i tried doing

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, xxx);

curl_easy_setopt(curl, CURLOPT_URL, URL);

then  i tried

curl_easy_setopt(curl, CURLOPT_POSTFIELDS, p_data)

(where p_data contain file data i read in from xxx file first)

but that did not seem to work

i tried using

fd = fopen("xxx", "r");

fsize = file size of xxx

curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_func);

curl_easy_setopt(curl, CURLOPT_READDATA, fd);

curl_easy_setopt(curl, CURLOP_INFILESIZE_LARGE, fsize);

but it did not seem to call the read_func at all

can someone assist how to implement -data function in C  where the file
is large ???


This email has been checked for viruses by Avast antivirus software.
Received on 2018-04-08