| 1 |
.\" ************************************************************************** |
| 2 |
.\" * _ _ ____ _ |
| 3 |
.\" * Project ___| | | | _ \| | |
| 4 |
.\" * / __| | | | |_) | | |
| 5 |
.\" * | (__| |_| | _ <| |___ |
| 6 |
.\" * \___|\___/|_| \_\_____| |
| 7 |
.\" * |
| 8 |
.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, et al. |
| 9 |
.\" * |
| 10 |
.\" * This software is licensed as described in the file COPYING, which |
| 11 |
.\" * you should have received as part of this distribution. The terms |
| 12 |
.\" * are also available at https://curl.haxx.se/docs/copyright.html. |
| 13 |
.\" * |
| 14 |
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 |
.\" * copies of the Software, and permit persons to whom the Software is |
| 16 |
.\" * furnished to do so, under the terms of the COPYING file. |
| 17 |
.\" * |
| 18 |
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 |
.\" * KIND, either express or implied. |
| 20 |
.\" * |
| 21 |
.\" ************************************************************************** |
| 22 |
.\" |
| 23 |
.TH CURLOPT_POST 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options" |
| 24 |
.SH NAME |
| 25 |
CURLOPT_POST \- request an HTTP POST |
| 26 |
.SH SYNOPSIS |
| 27 |
#include <curl/curl.h> |
| 28 |
|
| 29 |
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post); |
| 30 |
.SH DESCRIPTION |
| 31 |
A parameter set to 1 tells libcurl to do a regular HTTP post. This will also |
| 32 |
make the library use a "Content-Type: application/x-www-form-urlencoded" |
| 33 |
header. (This is by far the most commonly used POST method). |
| 34 |
|
| 35 |
Use one of \fICURLOPT_POSTFIELDS(3)\fP or \fICURLOPT_COPYPOSTFIELDS(3)\fP |
| 36 |
options to specify what data to post and \fICURLOPT_POSTFIELDSIZE(3)\fP or |
| 37 |
\fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP to set the data size. |
| 38 |
|
| 39 |
Optionally, you can provide data to POST using the |
| 40 |
\fICURLOPT_READFUNCTION(3)\fP and \fICURLOPT_READDATA(3)\fP options but then |
| 41 |
you must make sure to not set \fICURLOPT_POSTFIELDS(3)\fP to anything but |
| 42 |
NULL. When providing data with a callback, you must transmit it using chunked |
| 43 |
transfer-encoding or you must set the size of the data with the |
| 44 |
\fICURLOPT_POSTFIELDSIZE(3)\fP or \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP |
| 45 |
options. To enable chunked encoding, you simply pass in the appropriate |
| 46 |
Transfer-Encoding header, see the post-callback.c example. |
| 47 |
|
| 48 |
You can override the default POST Content-Type: header by setting your own |
| 49 |
with \fICURLOPT_HTTPHEADER(3)\fP. |
| 50 |
|
| 51 |
Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. |
| 52 |
You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual. |
| 53 |
|
| 54 |
If you use POST to an HTTP 1.1 server, you can send data without knowing the |
| 55 |
size before starting the POST if you use chunked encoding. You enable this by |
| 56 |
adding a header like "Transfer-Encoding: chunked" with |
| 57 |
\fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you |
| 58 |
must specify the size in the request. (Since 7.66.0, libcurl will |
| 59 |
automatically use chunked encoding for POSTs if the size is unknown.) |
| 60 |
|
| 61 |
When setting \fICURLOPT_POST(3)\fP to 1, libcurl will automatically set |
| 62 |
\fICURLOPT_NOBODY(3)\fP and \fICURLOPT_HTTPGET(3)\fP to 0. |
| 63 |
|
| 64 |
If you issue a POST request and then want to make a HEAD or GET using the same |
| 65 |
re-used handle, you must explicitly set the new request type using |
| 66 |
\fICURLOPT_NOBODY(3)\fP or \fICURLOPT_HTTPGET(3)\fP or similar. |
| 67 |
.SH DEFAULT |
| 68 |
0, disabled |
| 69 |
.SH PROTOCOLS |
| 70 |
HTTP |
| 71 |
.SH EXAMPLE |
| 72 |
.nf |
| 73 |
CURL *curl = curl_easy_init(); |
| 74 |
if(curl) { |
| 75 |
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/foo.bin"); |
| 76 |
curl_easy_setopt(curl, CURLOPT_POST, 1L); |
| 77 |
|
| 78 |
/* set up the read callback with CURLOPT_READFUNCTION */ |
| 79 |
|
| 80 |
ret = curl_easy_perform(curl); |
| 81 |
|
| 82 |
curl_easy_cleanup(curl); |
| 83 |
} |
| 84 |
.fi |
| 85 |
.SH AVAILABILITY |
| 86 |
Along with HTTP |
| 87 |
.SH RETURN VALUE |
| 88 |
Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. |
| 89 |
.SH "SEE ALSO" |
| 90 |
.BR CURLOPT_POSTFIELDS "(3), " CURLOPT_HTTPPOST "(3), " |