CURLOPT_COPYPOSTFIELDS.3 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .\" generated by cd2nroff 0.1 from CURLOPT_COPYPOSTFIELDS.md
  2. .TH CURLOPT_COPYPOSTFIELDS 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_COPYPOSTFIELDS \- have libcurl copy data to POST
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a char pointer as parameter, which should be the full \fIdata\fP to post in a
  12. HTTP POST operation. It behaves as the \fICURLOPT_POSTFIELDS(3)\fP option, but the
  13. original data is instead copied by the library, allowing the application to
  14. overwrite the original data after setting this option.
  15. Because data are copied, care must be taken when using this option in
  16. conjunction with \fICURLOPT_POSTFIELDSIZE(3)\fP or
  17. \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP: If the size has not been set prior to
  18. \fICURLOPT_COPYPOSTFIELDS(3)\fP, the data is assumed to be a null\-terminated
  19. string; else the stored size informs the library about the byte count to
  20. copy. In any case, the size must not be changed after
  21. \fICURLOPT_COPYPOSTFIELDS(3)\fP, unless another \fICURLOPT_POSTFIELDS(3)\fP or
  22. \fICURLOPT_COPYPOSTFIELDS(3)\fP option is issued.
  23. .SH DEFAULT
  24. NULL
  25. .SH PROTOCOLS
  26. This functionality affects http only
  27. .SH EXAMPLE
  28. .nf
  29. int main(void)
  30. {
  31. CURL *curl = curl_easy_init();
  32. if(curl) {
  33. char local_buffer[1024]="data to send";
  34. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  35. /* size of the data to copy from the buffer and send in the request */
  36. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
  37. /* send data from the local stack */
  38. curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);
  39. curl_easy_perform(curl);
  40. }
  41. }
  42. .fi
  43. .SH AVAILABILITY
  44. Added in curl 7.17.1
  45. .SH RETURN VALUE
  46. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  47. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  48. .SH SEE ALSO
  49. .BR CURLOPT_MIMEPOST (3),
  50. .BR CURLOPT_POSTFIELDS (3),
  51. .BR CURLOPT_POSTFIELDSIZE (3),
  52. .BR CURLOPT_UPLOAD (3)