CURLOPT_POST.3 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .\" generated by cd2nroff 0.1 from CURLOPT_POST.md
  2. .TH CURLOPT_POST 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_POST \- make an HTTP POST
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
  9. .fi
  10. .SH DESCRIPTION
  11. A parameter set to 1 tells libcurl to do a regular HTTP post. This also makes
  12. libcurl use a "Content\-Type: application/x\-www\-form\-urlencoded" header. This
  13. is the most commonly used POST method.
  14. Use one of \fICURLOPT_POSTFIELDS(3)\fP or \fICURLOPT_COPYPOSTFIELDS(3)\fP
  15. options to specify what data to post and \fICURLOPT_POSTFIELDSIZE(3)\fP or
  16. \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP to set the data size.
  17. Optionally, you can provide data to POST using the
  18. \fICURLOPT_READFUNCTION(3)\fP and \fICURLOPT_READDATA(3)\fP options but then
  19. you must make sure to not set \fICURLOPT_POSTFIELDS(3)\fP to anything but
  20. NULL. When providing data with a callback, you must transmit it using chunked
  21. transfer\-encoding or you must set the size of the data with the
  22. \fICURLOPT_POSTFIELDSIZE(3)\fP or \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP
  23. options. To enable chunked encoding, you simply pass in the appropriate
  24. Transfer\-Encoding header, see the post\-callback.c example.
  25. You can override the default POST Content\-Type: header by setting your own
  26. with \fICURLOPT_HTTPHEADER(3)\fP.
  27. Using POST with HTTP 1.1 implies the use of a "Expect: 100\-continue" header.
  28. You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
  29. If you use POST to an HTTP 1.1 server, you can send data without knowing the
  30. size before starting the POST if you use chunked encoding. You enable this by
  31. adding a header like "Transfer\-Encoding: chunked" with
  32. \fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
  33. must specify the size in the request. (Since 7.66.0, libcurl automatically
  34. uses chunked encoding for POSTs if the size is unknown.)
  35. When setting \fICURLOPT_POST(3)\fP to 1, libcurl automatically sets
  36. \fICURLOPT_NOBODY(3)\fP and \fICURLOPT_HTTPGET(3)\fP to 0.
  37. If you issue a POST request and then want to make a HEAD or GET using the same
  38. reused handle, you must explicitly set the new request type using
  39. \fICURLOPT_NOBODY(3)\fP or \fICURLOPT_HTTPGET(3)\fP or similar.
  40. When setting \fICURLOPT_POST(3)\fP to 0, libcurl resets the request type to the
  41. default to disable the POST. Typically that means gets reset to GET. Instead
  42. you should set a new request type explicitly as described above.
  43. .SH DEFAULT
  44. 0, disabled
  45. .SH PROTOCOLS
  46. This functionality affects http only
  47. .SH EXAMPLE
  48. .nf
  49. int main(void)
  50. {
  51. CURL *curl = curl_easy_init();
  52. if(curl) {
  53. CURLcode res;
  54. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  55. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  56. /* set up the read callback with CURLOPT_READFUNCTION */
  57. res = curl_easy_perform(curl);
  58. curl_easy_cleanup(curl);
  59. }
  60. }
  61. .fi
  62. .SH AVAILABILITY
  63. Added in curl 7.1
  64. .SH RETURN VALUE
  65. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  66. .SH SEE ALSO
  67. .BR CURLOPT_HTTPPOST (3),
  68. .BR CURLOPT_POSTFIELDS (3),
  69. .BR CURLOPT_UPLOAD (3)