1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_POSTFIELDSIZE 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_POSTFIELDS (3) 9 - CURLOPT_POSTFIELDSIZE_LARGE (3) 10--- 11 12# NAME 13 14CURLOPT_POSTFIELDSIZE - size of POST data pointed to 15 16# SYNOPSIS 17 18~~~c 19#include <curl/curl.h> 20 21CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDSIZE, long size); 22~~~ 23 24# DESCRIPTION 25 26If you want to post static data to the server without having libcurl do a 27strlen() to measure the data size, this option must be used. When this option 28is used you can post fully binary data, which otherwise is likely to fail. If 29this size is set to -1, libcurl uses strlen() to get the size or relies on the 30CURLOPT_READFUNCTION(3) (if used) to signal the end of data. 31 32If you post more than 2GB, use CURLOPT_POSTFIELDSIZE_LARGE(3). 33 34# DEFAULT 35 36-1 37 38# PROTOCOLS 39 40HTTP 41 42# EXAMPLE 43 44~~~c 45#include <string.h> /* for strlen */ 46 47int main(void) 48{ 49 CURL *curl = curl_easy_init(); 50 if(curl) { 51 const char *data = "data to send"; 52 53 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 54 55 /* size of the POST data */ 56 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data)); 57 58 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); 59 60 curl_easy_perform(curl); 61 } 62} 63~~~ 64 65# AVAILABILITY 66 67Along with HTTP 68 69# RETURN VALUE 70 71Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. 72