CURLOPT_POST.3 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_POST 3 "17 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_POST \- make an HTTP POST
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POST, long post);
  32. .fi
  33. .SH DESCRIPTION
  34. A parameter set to 1 tells libcurl to do a regular HTTP post. This will also
  35. make the library use a "Content-Type: application/x-www-form-urlencoded"
  36. header. (This is by far the most commonly used POST method).
  37. Use one of \fICURLOPT_POSTFIELDS(3)\fP or \fICURLOPT_COPYPOSTFIELDS(3)\fP
  38. options to specify what data to post and \fICURLOPT_POSTFIELDSIZE(3)\fP or
  39. \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP to set the data size.
  40. Optionally, you can provide data to POST using the
  41. \fICURLOPT_READFUNCTION(3)\fP and \fICURLOPT_READDATA(3)\fP options but then
  42. you must make sure to not set \fICURLOPT_POSTFIELDS(3)\fP to anything but
  43. NULL. When providing data with a callback, you must transmit it using chunked
  44. transfer-encoding or you must set the size of the data with the
  45. \fICURLOPT_POSTFIELDSIZE(3)\fP or \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP
  46. options. To enable chunked encoding, you simply pass in the appropriate
  47. Transfer-Encoding header, see the post-callback.c example.
  48. You can override the default POST Content-Type: header by setting your own
  49. with \fICURLOPT_HTTPHEADER(3)\fP.
  50. Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
  51. You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
  52. If you use POST to an HTTP 1.1 server, you can send data without knowing the
  53. size before starting the POST if you use chunked encoding. You enable this by
  54. adding a header like "Transfer-Encoding: chunked" with
  55. \fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
  56. must specify the size in the request. (Since 7.66.0, libcurl will
  57. automatically use chunked encoding for POSTs if the size is unknown.)
  58. When setting \fICURLOPT_POST(3)\fP to 1, libcurl will automatically set
  59. \fICURLOPT_NOBODY(3)\fP and \fICURLOPT_HTTPGET(3)\fP to 0.
  60. If you issue a POST request and then want to make a HEAD or GET using the same
  61. re-used handle, you must explicitly set the new request type using
  62. \fICURLOPT_NOBODY(3)\fP or \fICURLOPT_HTTPGET(3)\fP or similar.
  63. When setting \fICURLOPT_POST(3)\fP to 0, libcurl resets the request type to
  64. the default to disable the POST. Typically that would mean it's reset to GET.
  65. Instead you should set a new request type explicitly as described above.
  66. .SH DEFAULT
  67. 0, disabled
  68. .SH PROTOCOLS
  69. HTTP
  70. .SH EXAMPLE
  71. .nf
  72. CURL *curl = curl_easy_init();
  73. if(curl) {
  74. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  75. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  76. /* set up the read callback with CURLOPT_READFUNCTION */
  77. ret = curl_easy_perform(curl);
  78. curl_easy_cleanup(curl);
  79. }
  80. .fi
  81. .SH AVAILABILITY
  82. Along with HTTP
  83. .SH RETURN VALUE
  84. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  85. .SH "SEE ALSO"
  86. .BR CURLOPT_POSTFIELDS "(3), " CURLOPT_HTTPPOST "(3), "