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