CURLOPT_POST.3 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_POST 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_POST \- make an HTTP POST
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
  30. .fi
  31. .SH DESCRIPTION
  32. A parameter set to 1 tells libcurl to do a regular HTTP post. This will also
  33. make the library use a "Content-Type: application/x-www-form-urlencoded"
  34. header. (This is by far the most commonly used POST method).
  35. Use one of \fICURLOPT_POSTFIELDS(3)\fP or \fICURLOPT_COPYPOSTFIELDS(3)\fP
  36. options to specify what data to post and \fICURLOPT_POSTFIELDSIZE(3)\fP or
  37. \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP to set the data size.
  38. Optionally, you can provide data to POST using the
  39. \fICURLOPT_READFUNCTION(3)\fP and \fICURLOPT_READDATA(3)\fP options but then
  40. you must make sure to not set \fICURLOPT_POSTFIELDS(3)\fP to anything but
  41. NULL. When providing data with a callback, you must transmit it using chunked
  42. transfer-encoding or you must set the size of the data with the
  43. \fICURLOPT_POSTFIELDSIZE(3)\fP or \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP
  44. options. To enable chunked encoding, you simply pass in the appropriate
  45. Transfer-Encoding header, see the post-callback.c example.
  46. You can override the default POST Content-Type: header by setting your own
  47. with \fICURLOPT_HTTPHEADER(3)\fP.
  48. Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
  49. You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
  50. If you use POST to an HTTP 1.1 server, you can send data without knowing the
  51. size before starting the POST if you use chunked encoding. You enable this by
  52. adding a header like "Transfer-Encoding: chunked" with
  53. \fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
  54. must specify the size in the request. (Since 7.66.0, libcurl will
  55. automatically use chunked encoding for POSTs if the size is unknown.)
  56. When setting \fICURLOPT_POST(3)\fP to 1, libcurl will automatically set
  57. \fICURLOPT_NOBODY(3)\fP and \fICURLOPT_HTTPGET(3)\fP to 0.
  58. If you issue a POST request and then want to make a HEAD or GET using the same
  59. re-used handle, you must explicitly set the new request type using
  60. \fICURLOPT_NOBODY(3)\fP or \fICURLOPT_HTTPGET(3)\fP or similar.
  61. .SH DEFAULT
  62. 0, disabled
  63. .SH PROTOCOLS
  64. HTTP
  65. .SH EXAMPLE
  66. .nf
  67. CURL *curl = curl_easy_init();
  68. if(curl) {
  69. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  70. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  71. /* set up the read callback with CURLOPT_READFUNCTION */
  72. ret = curl_easy_perform(curl);
  73. curl_easy_cleanup(curl);
  74. }
  75. .fi
  76. .SH AVAILABILITY
  77. Along with HTTP
  78. .SH RETURN VALUE
  79. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  80. .SH "SEE ALSO"
  81. .BR CURLOPT_POSTFIELDS "(3), " CURLOPT_HTTPPOST "(3), "