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 *post‐
12       data);
13

DESCRIPTION

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

DEFAULT

56       NULL
57

PROTOCOLS

59       HTTP
60

EXAMPLE

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

AVAILABILITY

78       Always
79

RETURN VALUE

81       Returns CURLE_OK
82

SEE ALSO

84       CURLOPT_POSTFIELDSIZE(3), CURLOPT_READFUNCTION(3),
85
86
87
88libcurl 7.79.1                September 08, 2021         CURLOPT_POSTFIELDS(3)
Impressum