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

NAME

6       CURLOPT_POSTFIELDS - specify 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
18       encode  it  for  you in any way. For example, the web server may assume
19       that 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 behaviour 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       Using  POST  with  HTTP 1.1 implies the use of a "Expect: 100-continue"
43       header, and libcurl will add that header automatically if the  POST  is
44       either  known to be larger than 1MB or if the expected size is unknown.
45       You can disable this header with CURLOPT_HTTPHEADER(3) as usual.
46
47       To make multipart/formdata posts (aka  RFC2388-posts),  check  out  the
48       CURLOPT_HTTPPOST(3) option combined with curl_formadd(3).
49

DEFAULT

51       NULL
52

PROTOCOLS

54       HTTP
55

EXAMPLE

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

AVAILABILITY

73       Always
74

RETURN VALUE

76       Returns CURLE_OK
77

SEE ALSO

79       CURLOPT_POSTFIELDSIZE(3), CURLOPT_READFUNCTION(3),
80
81
82
83libcurl 7.71.1                  March 23, 2020           CURLOPT_POSTFIELDS(3)
Impressum