Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
CURLOPT_POSTFIELDS(3) | Library Functions Manual | CURLOPT_POSTFIELDS(3) |
NAME
CURLOPT_POSTFIELDS - data to POST to serverSYNOPSIS
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
DESCRIPTION
Pass a char pointer as parameter, pointing to the data buffer to use in an HTTP POST operation or an MQTT subscribe. The data must be formatted and encoded the way you want the server to receive it. libcurl does not convert or encode it in any way. For example, a web server may assume that this data is URL encoded.DEFAULT
NULLPROTOCOLS
This functionality affects http and mqttEXAMPLE
/* send an application/x-www-form-urlencoded POST */
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
const char *data = "data to send";
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* size of the POST data if strlen() is not good enough */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
/* pass in a pointer to the data - libcurl does not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
}
/* send an application/json POST */
curl = curl_easy_init();
if(curl) {
const char *json = "{\"name\": \"daniel\"}";
struct curl_slist *slist1 = NULL;
slist1 = curl_slist_append(slist1, "Content-Type: application/json");
slist1 = curl_slist_append(slist1, "Accept: application/json");
/* set custom headers */
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* pass in a pointer to the data - libcurl does not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
}
}
AVAILABILITY
Added in curl 7.1RETURN VALUE
Returns CURLE_OKSEE ALSO
CURLOPT_COPYPOSTFIELDS(3), CURLOPT_MIMEPOST(3), CURLOPT_POSTFIELDSIZE(3), CURLOPT_READFUNCTION(3), CURLOPT_UPLOAD(3)2024-11-23 | libcurl |