2014-06-18 06:29:22 +08:00
|
|
|
.\" **************************************************************************
|
|
|
|
.\" * _ _ ____ _
|
|
|
|
.\" * Project ___| | | | _ \| |
|
|
|
|
.\" * / __| | | | |_) | |
|
|
|
|
.\" * | (__| |_| | _ <| |___
|
|
|
|
.\" * \___|\___/|_| \_\_____|
|
|
|
|
.\" *
|
2021-04-23 23:14:58 +08:00
|
|
|
.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2014-06-18 06:29:22 +08:00
|
|
|
.\" *
|
|
|
|
.\" * This software is licensed as described in the file COPYING, which
|
|
|
|
.\" * you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
.\" * are also available at https://curl.se/docs/copyright.html.
|
2014-06-18 06:29:22 +08:00
|
|
|
.\" *
|
|
|
|
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
.\" * copies of the Software, and permit persons to whom the Software is
|
|
|
|
.\" * furnished to do so, under the terms of the COPYING file.
|
|
|
|
.\" *
|
|
|
|
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
.\" * KIND, either express or implied.
|
|
|
|
.\" *
|
|
|
|
.\" **************************************************************************
|
|
|
|
.\"
|
|
|
|
.TH CURLOPT_POSTFIELDS 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
|
|
|
|
.SH NAME
|
2021-09-09 04:55:58 +08:00
|
|
|
CURLOPT_POSTFIELDS \- data to POST to server
|
2014-06-18 06:29:22 +08:00
|
|
|
.SH SYNOPSIS
|
2021-11-26 21:20:18 +08:00
|
|
|
.nf
|
2014-06-18 06:29:22 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
|
2021-11-26 21:20:18 +08:00
|
|
|
.fi
|
2014-06-18 06:29:22 +08:00
|
|
|
.SH DESCRIPTION
|
2018-04-18 03:17:57 +08:00
|
|
|
Pass a char * as parameter, pointing to the full data to send in an HTTP POST
|
2014-06-18 06:29:22 +08:00
|
|
|
operation. You must make sure that the data is formatted the way you want the
|
|
|
|
server to receive it. libcurl will not convert or encode it for you in any
|
|
|
|
way. For example, the web server may assume that this data is url-encoded.
|
|
|
|
|
|
|
|
The data pointed to is NOT copied by the library: as a consequence, it must be
|
|
|
|
preserved by the calling application until the associated transfer finishes.
|
2020-12-31 17:11:49 +08:00
|
|
|
This behavior can be changed (so libcurl does copy the data) by setting the
|
2014-11-20 17:27:09 +08:00
|
|
|
\fICURLOPT_COPYPOSTFIELDS(3)\fP option.
|
2014-06-18 06:29:22 +08:00
|
|
|
|
|
|
|
This POST is a normal application/x-www-form-urlencoded kind (and libcurl will
|
|
|
|
set that Content-Type by default when this option is used), which is commonly
|
|
|
|
used by HTML forms. Change Content-Type with \fICURLOPT_HTTPHEADER(3)\fP.
|
|
|
|
|
2015-05-20 13:48:31 +08:00
|
|
|
You can use \fIcurl_easy_escape(3)\fP to url-encode your data, if necessary. It
|
|
|
|
returns a pointer to an encoded string that can be passed as \fIpostdata\fP.
|
|
|
|
|
2018-05-21 16:26:24 +08:00
|
|
|
Using \fICURLOPT_POSTFIELDS(3)\fP implies setting \fICURLOPT_POST(3)\fP to 1.
|
2016-06-12 05:33:16 +08:00
|
|
|
|
|
|
|
If \fICURLOPT_POSTFIELDS(3)\fP is explicitly set to NULL then libcurl will get
|
|
|
|
the POST data from the read callback. If you want to send a zero-byte POST set
|
|
|
|
\fICURLOPT_POSTFIELDS(3)\fP to an empty string, or set \fICURLOPT_POST(3)\fP to
|
|
|
|
1 and \fICURLOPT_POSTFIELDSIZE(3)\fP to 0.
|
2014-06-18 06:29:22 +08:00
|
|
|
|
2021-04-23 23:14:58 +08:00
|
|
|
libcurl will use assume this option points to a nul-terminated string unless
|
|
|
|
you also set \fICURLOPT_POSTFIELDSIZE(3)\fP to specify the length of the
|
|
|
|
provided data, which then is strictly required if you want to send off nul
|
|
|
|
bytes included in the data.
|
|
|
|
|
2017-07-07 18:43:17 +08:00
|
|
|
Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header,
|
|
|
|
and libcurl will add that header automatically if the POST is either known to
|
2020-01-14 22:34:56 +08:00
|
|
|
be larger than 1MB or if the expected size is unknown. You can disable this
|
|
|
|
header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
|
2014-06-18 06:29:22 +08:00
|
|
|
|
|
|
|
To make multipart/formdata posts (aka RFC2388-posts), check out the
|
|
|
|
\fICURLOPT_HTTPPOST(3)\fP option combined with \fIcurl_formadd(3)\fP.
|
|
|
|
.SH DEFAULT
|
|
|
|
NULL
|
|
|
|
.SH PROTOCOLS
|
|
|
|
HTTP
|
|
|
|
.SH EXAMPLE
|
2014-10-21 14:58:03 +08:00
|
|
|
.nf
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
if(curl) {
|
|
|
|
const char *data = "data to send";
|
|
|
|
|
2020-09-17 05:04:07 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
2014-10-21 14:58:03 +08:00
|
|
|
|
|
|
|
/* size of the POST data */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
|
|
|
|
|
|
|
|
/* pass in a pointer to the data - libcurl will not copy */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
|
|
|
|
|
|
|
curl_easy_perform(curl);
|
|
|
|
}
|
|
|
|
.fi
|
2014-06-18 06:29:22 +08:00
|
|
|
.SH AVAILABILITY
|
|
|
|
Always
|
|
|
|
.SH RETURN VALUE
|
|
|
|
Returns CURLE_OK
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR CURLOPT_POSTFIELDSIZE "(3), " CURLOPT_READFUNCTION "(3), "
|