1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_COPYPOSTFIELDS 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_MIMEPOST (3) 9 - CURLOPT_POSTFIELDS (3) 10 - CURLOPT_POSTFIELDSIZE (3) 11 - CURLOPT_UPLOAD (3) 12--- 13 14# NAME 15 16CURLOPT_COPYPOSTFIELDS - have libcurl copy data to POST 17 18# SYNOPSIS 19 20~~~c 21#include <curl/curl.h> 22 23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data); 24~~~ 25 26# DESCRIPTION 27 28Pass a char pointer as parameter, which should be the full *data* to post in a 29HTTP POST operation. It behaves as the CURLOPT_POSTFIELDS(3) option, but the 30original data is instead copied by the library, allowing the application to 31overwrite the original data after setting this option. 32 33Because data are copied, care must be taken when using this option in 34conjunction with CURLOPT_POSTFIELDSIZE(3) or 35CURLOPT_POSTFIELDSIZE_LARGE(3): If the size has not been set prior to 36CURLOPT_COPYPOSTFIELDS(3), the data is assumed to be a null-terminated 37string; else the stored size informs the library about the byte count to 38copy. In any case, the size must not be changed after 39CURLOPT_COPYPOSTFIELDS(3), unless another CURLOPT_POSTFIELDS(3) or 40CURLOPT_COPYPOSTFIELDS(3) option is issued. 41 42# DEFAULT 43 44NULL 45 46# PROTOCOLS 47 48HTTP(S) 49 50# EXAMPLE 51 52~~~c 53int main(void) 54{ 55 CURL *curl = curl_easy_init(); 56 if(curl) { 57 char local_buffer[1024]="data to send"; 58 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 59 60 /* size of the data to copy from the buffer and send in the request */ 61 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L); 62 63 /* send data from the local stack */ 64 curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer); 65 66 curl_easy_perform(curl); 67 } 68} 69~~~ 70 71# AVAILABILITY 72 73Added in 7.17.1 74 75# RETURN VALUE 76 77Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or 78CURLE_OUT_OF_MEMORY if there was insufficient heap space. 79