Imported Upstream version 7.59.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_POST.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, 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 "May 05, 2017" "libcurl 7.59.0" "curl_easy_setopt options"
24
25 .SH NAME
26 CURLOPT_POST \- request a HTTP POST
27 .SH SYNOPSIS
28 #include <curl/curl.h>
29
30 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
31 .SH DESCRIPTION
32 A parameter set to 1 tells libcurl to do a regular HTTP post. This will also
33 make the library use a "Content-Type: application/x-www-form-urlencoded"
34 header. (This is by far the most commonly used POST method).
35
36 Use one of \fICURLOPT_POSTFIELDS(3)\fP or \fICURLOPT_COPYPOSTFIELDS(3)\fP
37 options to specify what data to post and \fICURLOPT_POSTFIELDSIZE(3)\fP or
38 \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP to set the data size.
39
40 Optionally, you can provide data to POST using the
41 \fICURLOPT_READFUNCTION(3)\fP and \fICURLOPT_READDATA(3)\fP options but then
42 you must make sure to not set \fICURLOPT_POSTFIELDS(3)\fP to anything but
43 NULL. When providing data with a callback, you must transmit it using chunked
44 transfer-encoding or you must set the size of the data with the
45 \fICURLOPT_POSTFIELDSIZE(3)\fP or \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP
46 options. To enable chunked encoding, you simply pass in the appropriate
47 Transfer-Encoding header, see the post-callback.c example.
48
49 You can override the default POST Content-Type: header by setting your own
50 with \fICURLOPT_HTTPHEADER(3)\fP.
51
52 Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
53 You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
54
55 If you use POST to a HTTP 1.1 server, you can send data without knowing the
56 size before starting the POST if you use chunked encoding. You enable this by
57 adding a header like "Transfer-Encoding: chunked" with
58 \fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
59 must specify the size in the request.
60
61 When setting \fICURLOPT_POST(3)\fP to 1, it will automatically set
62 \fICURLOPT_NOBODY(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), "