1CURLOPT_POST(3)            curl_easy_setopt options            CURLOPT_POST(3)
2
3
4

NAME

6       CURLOPT_POST - request an HTTP POST
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
12

DESCRIPTION

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. (Since 7.66.0, libcurl will auto‐
44       matically use chunked encoding for POSTs if the size is unknown.)
45
46       When  setting CURLOPT_POST(3) to 1, libcurl will automatically set CUR‐
47       LOPT_NOBODY(3) and CURLOPT_HTTPGET(3) to 0.
48
49       If you issue a POST request and then want to make a HEAD or  GET  using
50       the  same  re-used handle, you must explicitly set the new request type
51       using CURLOPT_NOBODY(3) or CURLOPT_HTTPGET(3) or similar.
52

DEFAULT

54       0, disabled
55

PROTOCOLS

57       HTTP
58

EXAMPLE

60       CURL *curl = curl_easy_init();
61       if(curl) {
62         curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/foo.bin");
63         curl_easy_setopt(curl, CURLOPT_POST, 1L);
64
65         /* set up the read callback with CURLOPT_READFUNCTION */
66
67         ret = curl_easy_perform(curl);
68
69         curl_easy_cleanup(curl);
70       }
71

AVAILABILITY

73       Along with HTTP
74

RETURN VALUE

76       Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
77

SEE ALSO

79       CURLOPT_POSTFIELDS(3), CURLOPT_HTTPPOST(3),
80
81
82
83libcurl 7.69.1                   July 22, 2019                 CURLOPT_POST(3)
Impressum