Discussion:
File Upload POST using libcurl
koderr
2008-11-08 12:59:21 UTC
Permalink
How I can do this:

curl -F upload=@localfilename -F press=OK [URL]

using libcurl?

Tried the following options:

curl_easy_setopt(curl_handle, CURLOPT_URL, szUrl);
curl_easy_setopt(curl_handle, CURLOPT_REFERER, szUrl);
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, szPostData);
curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_POST, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_READDATA, fd);
curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl_handle, CURLOPT_COOKIE, szCookie);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, szAgent);

It does PUT with "Expect: 100-continue".
--
Best regards,
koderr mailto:***@bk.ru
Dan Fandrich
2008-11-09 05:19:26 UTC
Permalink
Post by koderr
using libcurl?
The --libcurl option is one way to find out.
Post by koderr
curl_easy_setopt(curl_handle, CURLOPT_URL, szUrl);
curl_easy_setopt(curl_handle, CURLOPT_REFERER, szUrl);
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, szPostData);
From the manual for CURLOPT_POSTFIELDS: This POST is a normal
application/x-www-form-urlencoded kind...To make multipart/formdata
posts check out the CURLOPT_HTTPPOST option.
Post by koderr
curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, TRUE);
From the manual for CURLOPT_UPLOAD: "If the protocol is HTTP, uploading
means using the PUT request." Don't use this if you want a POST.
Post by koderr
curl_easy_setopt(curl_handle, CURLOPT_POST, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_READDATA, fd);
curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl_handle, CURLOPT_COOKIE, szCookie);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, szAgent);
It does PUT with "Expect: 100-continue".
Use curl_formadd to create the right post data and CURLOPT_HTTPPOST to
specify it. Take a look at the postit2.c example program to start.
Post by koderr
Dan
--
http://www.MoveAnnouncer.com The web change of address service
Let webmasters know that your web site has moved
Continue reading on narkive:
Search results for 'File Upload POST using libcurl' (Questions and Answers)
3
replies
HTTP file upload using PHP without libcurl?
started 2010-10-04 08:29:42 UTC
programming & design
Loading...