Annotation of embedaddon/curl/docs/libcurl/opts/CURLOPT_POSTFIELDS.3, revision 1.1
1.1 ! misho 1: .\" **************************************************************************
! 2: .\" * _ _ ____ _
! 3: .\" * Project ___| | | | _ \| |
! 4: .\" * / __| | | | |_) | |
! 5: .\" * | (__| |_| | _ <| |___
! 6: .\" * \___|\___/|_| \_\_____|
! 7: .\" *
! 8: .\" * Copyright (C) 1998 - 2020, 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_POSTFIELDS 3 "March 23, 2020" "libcurl 7.70.0" "curl_easy_setopt options"
! 24:
! 25: .SH NAME
! 26: CURLOPT_POSTFIELDS \- specify data to POST to server
! 27: .SH SYNOPSIS
! 28: #include <curl/curl.h>
! 29:
! 30: CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
! 31: .SH DESCRIPTION
! 32: Pass a char * as parameter, pointing to the full data to send in an HTTP POST
! 33: operation. You must make sure that the data is formatted the way you want the
! 34: server to receive it. libcurl will not convert or encode it for you in any
! 35: way. For example, the web server may assume that this data is url-encoded.
! 36:
! 37: The data pointed to is NOT copied by the library: as a consequence, it must be
! 38: preserved by the calling application until the associated transfer finishes.
! 39: This behaviour can be changed (so libcurl does copy the data) by setting the
! 40: \fICURLOPT_COPYPOSTFIELDS(3)\fP option.
! 41:
! 42: This POST is a normal application/x-www-form-urlencoded kind (and libcurl will
! 43: set that Content-Type by default when this option is used), which is commonly
! 44: used by HTML forms. Change Content-Type with \fICURLOPT_HTTPHEADER(3)\fP.
! 45:
! 46: You can use \fIcurl_easy_escape(3)\fP to url-encode your data, if necessary. It
! 47: returns a pointer to an encoded string that can be passed as \fIpostdata\fP.
! 48:
! 49: Using \fICURLOPT_POSTFIELDS(3)\fP implies setting \fICURLOPT_POST(3)\fP to 1.
! 50:
! 51: If \fICURLOPT_POSTFIELDS(3)\fP is explicitly set to NULL then libcurl will get
! 52: the POST data from the read callback. If you want to send a zero-byte POST set
! 53: \fICURLOPT_POSTFIELDS(3)\fP to an empty string, or set \fICURLOPT_POST(3)\fP to
! 54: 1 and \fICURLOPT_POSTFIELDSIZE(3)\fP to 0.
! 55:
! 56: Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header,
! 57: and libcurl will add that header automatically if the POST is either known to
! 58: be larger than 1MB or if the expected size is unknown. You can disable this
! 59: header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
! 60:
! 61: To make multipart/formdata posts (aka RFC2388-posts), check out the
! 62: \fICURLOPT_HTTPPOST(3)\fP option combined with \fIcurl_formadd(3)\fP.
! 63: .SH DEFAULT
! 64: NULL
! 65: .SH PROTOCOLS
! 66: HTTP
! 67: .SH EXAMPLE
! 68: .nf
! 69: CURL *curl = curl_easy_init();
! 70: if(curl) {
! 71: const char *data = "data to send";
! 72:
! 73: curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
! 74:
! 75: /* size of the POST data */
! 76: curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
! 77:
! 78: /* pass in a pointer to the data - libcurl will not copy */
! 79: curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
! 80:
! 81: curl_easy_perform(curl);
! 82: }
! 83: .fi
! 84: .SH AVAILABILITY
! 85: Always
! 86: .SH RETURN VALUE
! 87: Returns CURLE_OK
! 88: .SH "SEE ALSO"
! 89: .BR CURLOPT_POSTFIELDSIZE "(3), " CURLOPT_READFUNCTION "(3), "
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>