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 1024 bytes or if the expected size is
45       unknown. You can disable  this  header  with  CURLOPT_HTTPHEADER(3)  as
46       usual.
47
48       To  make  multipart/formdata  posts  (aka RFC2388-posts), check out the
49       CURLOPT_HTTPPOST(3) option combined with curl_formadd(3).
50

DEFAULT

52       NULL
53

PROTOCOLS

55       HTTP
56

EXAMPLE

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

AVAILABILITY

74       Always
75

RETURN VALUE

77       Returns CURLE_OK
78

SEE ALSO

80       CURLOPT_POSTFIELDSIZE(3), CURLOPT_READFUNCTION(3),
81
82
83
84libcurl 7.61.1                   May 21, 2018            CURLOPT_POSTFIELDS(3)
Impressum