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

NAME

6       CURLOPT_POSTFIELDS - data to POST to server
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
12

DESCRIPTION

14       Pass  a  char  *  as parameter, pointing to the full data to send in an
15       HTTP POST operation. You must make sure that the data is formatted  the
16       way  you want the server to receive it. libcurl will not convert or en‐
17       code it for you in any way. For example, the web server may assume that
18       this data is url-encoded.
19
20       The  data pointed to is NOT copied by the library: as a consequence, it
21       must be preserved by  the  calling  application  until  the  associated
22       transfer  finishes.  This behavior can be changed (so libcurl does copy
23       the data) by setting the CURLOPT_COPYPOSTFIELDS(3) option.
24
25       This POST  is  a  normal  application/x-www-form-urlencoded  kind  (and
26       libcurl  will  set  that  Content-Type  by  default when this option is
27       used), which is commonly used by HTML forms. Change  Content-Type  with
28       CURLOPT_HTTPHEADER(3).
29
30       You  can use curl_easy_escape(3) to url-encode your data, if necessary.
31       It returns a pointer to an encoded string that can be passed  as  post‐
32       data.
33
34       Using CURLOPT_POSTFIELDS(3) implies setting CURLOPT_POST(3) to 1.
35
36       If  CURLOPT_POSTFIELDS(3)  is  explicitly set to NULL then libcurl will
37       get the POST data from the read callback. If you want to send  a  zero-
38       byte  POST  set  CURLOPT_POSTFIELDS(3)  to an empty string, or set CUR‐
39       LOPT_POST(3) to 1 and CURLOPT_POSTFIELDSIZE(3) to 0.
40
41       libcurl will use assume this option points to a  nul-terminated  string
42       unless  you  also set CURLOPT_POSTFIELDSIZE(3) to specify the length of
43       the provided data, which then is strictly required if you want to  send
44       off nul bytes included in the data.
45
46       Using  POST  with  HTTP 1.1 implies the use of a "Expect: 100-continue"
47       header, and libcurl will add that header automatically if the  POST  is
48       either  known to be larger than 1MB or if the expected size is unknown.
49       You can disable this header with CURLOPT_HTTPHEADER(3) as usual.
50
51       To make multipart/formdata posts (aka  RFC2388-posts),  check  out  the
52       CURLOPT_HTTPPOST(3) option combined with curl_formadd(3).
53

DEFAULT

55       NULL
56

PROTOCOLS

58       HTTP
59

EXAMPLE

61       CURL *curl = curl_easy_init();
62       if(curl) {
63         const char *data = "data to send";
64
65         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
66
67         /* size of the POST data */
68         curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
69
70         /* pass in a pointer to the data - libcurl will not copy */
71         curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
72
73         curl_easy_perform(curl);
74       }
75

AVAILABILITY

77       Always
78

RETURN VALUE

80       Returns CURLE_OK
81

SEE ALSO

83       CURLOPT_POSTFIELDSIZE(3), CURLOPT_READFUNCTION(3),
84
85
86
87libcurl 7.82.0                 November 26, 2021         CURLOPT_POSTFIELDS(3)
Impressum