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