2
0

CURLOPT_POST.3 3.8 KB

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