1CURLOPT_POST(3) curl_easy_setopt options CURLOPT_POST(3)
2
3
4
6 CURLOPT_POST - request an HTTP POST
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
12
14 A parameter set to 1 tells libcurl to do a regular HTTP post. This will
15 also make the library use a "Content-Type: application/x-www-form-
16 urlencoded" header. (This is by far the most commonly used POST
17 method).
18
19 Use one of CURLOPT_POSTFIELDS(3) or CURLOPT_COPYPOSTFIELDS(3) options
20 to specify what data to post and CURLOPT_POSTFIELDSIZE(3) or CUR‐
21 LOPT_POSTFIELDSIZE_LARGE(3) to set the data size.
22
23 Optionally, you can provide data to POST using the CURLOPT_READFUNC‐
24 TION(3) and CURLOPT_READDATA(3) options but then you must make sure to
25 not set CURLOPT_POSTFIELDS(3) to anything but NULL. When providing data
26 with a callback, you must transmit it using chunked transfer-encoding
27 or you must set the size of the data with the CURLOPT_POSTFIELDSIZE(3)
28 or CURLOPT_POSTFIELDSIZE_LARGE(3) options. To enable chunked encoding,
29 you simply pass in the appropriate Transfer-Encoding header, see the
30 post-callback.c example.
31
32 You can override the default POST Content-Type: header by setting your
33 own with CURLOPT_HTTPHEADER(3).
34
35 Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
36 header. You can disable this header with CURLOPT_HTTPHEADER(3) as
37 usual.
38
39 If you use POST to an HTTP 1.1 server, you can send data without know‐
40 ing the size before starting the POST if you use chunked encoding. You
41 enable this by adding a header like "Transfer-Encoding: chunked" with
42 CURLOPT_HTTPHEADER(3). With HTTP 1.0 or without chunked transfer, you
43 must specify the size in the request.
44
45 When setting CURLOPT_POST(3) to 1, libcurl will automatically set CUR‐
46 LOPT_NOBODY(3) and CURLOPT_HTTPGET(3) to 0.
47
48 If you issue a POST request and then want to make a HEAD or GET using
49 the same re-used handle, you must explicitly set the new request type
50 using CURLOPT_NOBODY(3) or CURLOPT_HTTPGET(3) or similar.
51
53 0, disabled
54
56 HTTP
57
59 CURL *curl = curl_easy_init();
60 if(curl) {
61 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/foo.bin");
62 curl_easy_setopt(curl, CURLOPT_POST, 1L);
63
64 /* set up the read callback with CURLOPT_READFUNCTION */
65
66 ret = curl_easy_perform(curl);
67
68 curl_easy_cleanup(curl);
69 }
70
72 Along with HTTP
73
75 Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
76
78 CURLOPT_POSTFIELDS(3), CURLOPT_HTTPPOST(3),
79
80
81
82libcurl 7.61.1 May 21, 2018 CURLOPT_POST(3)