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