GNURLOPT_POSTFIELDS(3)
πΈ GNURLOPT_POSTFIELDS(3) πΈ
okay bestie, welcome to this page from the curl_easy_setopt options manual β yes, thatβs the manual name, folded in right at the top like a lil name tag π«Ά. this one is about sending POST data, and itβs giving main character energy π
β¨ NAME β¨
CURLOPT_POSTFIELDS β specify data to POST to server π
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
β¨ DESCRIPTION β¨
so you pass a char * as the parameter, and it points to the full data youβre sending in an HTTP POST operation. you are the one responsible for making sure the data is formatted exactly how you want the server to receive it. libcurl will not convert or encode it for you in any way, periodt. like, the web server may assume that this data is url-encoded. thatβs on you, bestie.
β οΈ NO CAP WARNING: 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. this behaviour can be changed (so libcurl does copy the data) by setting the CURLOPT_COPYPOSTFIELDS(3) option. iconic behavior, but pls donβt forget the lifetime.
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 CURLOPT_HTTPHEADER(3).
you can use curl_easy_escape(3) to url-encode your data, if necessary. it returns a pointer to an encoded string that can be passed as postdata. slay β¨
using CURLOPT_POSTFIELDS(3) implies setting CURLOPT_POST(3) to 1. the way that works is lowkey automatic.
if CURLOPT_POSTFIELDS(3) 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 CURLOPT_POSTFIELDS(3) to an empty string, or set CURLOPT_POST(3) to 1 and CURLOPT_POSTFIELDSIZE(3) to 0. zero-byte queen π.
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 be larger than 1MB or if the expected size is unknown. you can disable this header with CURLOPT_HTTPHEADER(3) as usual.
to make multipart/formdata posts (aka RFC2388-posts), check out the CURLOPT_HTTPPOST(3) option combined with curl_formadd(3). iykyk π
π DEFAULT π
NULL
π¦ PROTOCOLS π¦
HTTP
β¨ EXAMPLE β¨
CURL *curl = curl_easy_init();
if(curl) {
const char *data = "data to send";
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* 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);
}
π AVAILABILITY π
Always
β RETURN VALUE β
Returns CURLE_OK
π SEE ALSO π
π okay thatβs the page, bestie β source/version: libcurl 7.37.0, dated 17 Jun 2014. mwah! π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms