CURLOPT_POSTFIELDS.3 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_POSTFIELDS 3 "17 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_POSTFIELDS \- data to POST to server
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDS, char *postdata);
  32. .fi
  33. .SH DESCRIPTION
  34. Pass a char * as parameter, pointing to the full data to send in an HTTP POST
  35. operation. You must make sure that the data is formatted the way you want the
  36. server to receive it. libcurl will not convert or encode it for you in any
  37. way. For example, the web server may assume that this data is URL encoded.
  38. The data pointed to is NOT copied by the library: as a consequence, it must be
  39. preserved by the calling application until the associated transfer finishes.
  40. This behavior can be changed (so libcurl does copy the data) by setting the
  41. \fICURLOPT_COPYPOSTFIELDS(3)\fP option.
  42. This POST is a normal \fBapplication/x-www-form-urlencoded\fP kind (and
  43. libcurl will set that Content-Type by default when this option is used), which
  44. is commonly used by HTML forms. Change Content-Type with
  45. \fICURLOPT_HTTPHEADER(3)\fP.
  46. You can use \fIcurl_easy_escape(3)\fP to URL encode your data, if
  47. necessary. It returns a pointer to an encoded string that can be passed as
  48. \fIpostdata\fP.
  49. Using \fICURLOPT_POSTFIELDS(3)\fP implies setting \fICURLOPT_POST(3)\fP to 1.
  50. If \fICURLOPT_POSTFIELDS(3)\fP is explicitly set to NULL then libcurl will get
  51. the POST data from the read callback. If you want to send a zero-byte POST set
  52. \fICURLOPT_POSTFIELDS(3)\fP to an empty string, or set \fICURLOPT_POST(3)\fP to
  53. 1 and \fICURLOPT_POSTFIELDSIZE(3)\fP to 0.
  54. libcurl will use assume this option points to a null-terminated string unless
  55. you also set \fICURLOPT_POSTFIELDSIZE(3)\fP to specify the length of the
  56. provided data, which then is strictly required if you want to send off null
  57. bytes included in the data.
  58. Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header,
  59. and libcurl will add that header automatically if the POST is either known to
  60. be larger than 1MB or if the expected size is unknown. You can disable this
  61. header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
  62. To make \fBmultipart/formdata\fP posts, check out the
  63. \fICURLOPT_MIMEPOST(3)\fP option combined with \fIcurl_mime_init(3)\fP.
  64. .SH DEFAULT
  65. NULL
  66. .SH PROTOCOLS
  67. HTTP
  68. .SH EXAMPLE
  69. .nf
  70. CURL *curl = curl_easy_init();
  71. if(curl) {
  72. const char *data = "data to send";
  73. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  74. /* size of the POST data */
  75. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
  76. /* pass in a pointer to the data - libcurl will not copy */
  77. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
  78. curl_easy_perform(curl);
  79. }
  80. .fi
  81. .SH AVAILABILITY
  82. Always
  83. .SH RETURN VALUE
  84. Returns CURLE_OK
  85. .SH "SEE ALSO"
  86. .BR CURLOPT_POSTFIELDSIZE "(3), " CURLOPT_READFUNCTION "(3), "
  87. .BR CURLOPT_MIMEPOST "(3), " CURLOPT_UPLOAD "(3), "