CURLOPT_HTTPPOST.3 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HTTPPOST.md
  2. .TH CURLOPT_HTTPPOST 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HTTPPOST \- multipart formpost content
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPPOST,
  9. struct curl_httppost *formpost);
  10. .fi
  11. .SH DESCRIPTION
  12. \fBThis option is deprecated.\fP Use \fICURLOPT_MIMEPOST(3)\fP instead.
  13. Tells libcurl you want a \fBmultipart/formdata\fP HTTP POST to be made and you
  14. instruct what data to pass on to the server in the \fIformpost\fP argument.
  15. Pass a pointer to a linked list of \fIcurl_httppost\fP structs as parameter.
  16. The easiest way to create such a list, is to use \fIcurl_formadd(3)\fP as
  17. documented. The data in this list must remain intact as long as the curl
  18. transfer is alive and is using it.
  19. Using POST with HTTP 1.1 implies the use of a "Expect: 100\-continue" header.
  20. You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP.
  21. When setting \fICURLOPT_HTTPPOST(3)\fP, libcurl automatically sets
  22. \fICURLOPT_NOBODY(3)\fP to 0.
  23. .SH DEFAULT
  24. NULL
  25. .SH PROTOCOLS
  26. This functionality affects http only
  27. .SH EXAMPLE
  28. .nf
  29. int main(void)
  30. {
  31. struct curl_httppost *formpost;
  32. struct curl_httppost *lastptr;
  33. /* Fill in the file upload field. This makes libcurl load data from
  34. the given file name when curl_easy_perform() is called. */
  35. curl_formadd(&formpost,
  36. &lastptr,
  37. CURLFORM_COPYNAME, "sendfile",
  38. CURLFORM_FILE, "postit2.c",
  39. CURLFORM_END);
  40. /* Fill in the filename field */
  41. curl_formadd(&formpost,
  42. &lastptr,
  43. CURLFORM_COPYNAME, "filename",
  44. CURLFORM_COPYCONTENTS, "postit2.c",
  45. CURLFORM_END);
  46. /* Fill in the submit field too, even if this is rarely needed */
  47. curl_formadd(&formpost,
  48. &lastptr,
  49. CURLFORM_COPYNAME, "submit",
  50. CURLFORM_COPYCONTENTS, "send",
  51. CURLFORM_END);
  52. CURL *curl = curl_easy_init();
  53. if(curl) {
  54. curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
  55. curl_easy_perform(curl);
  56. curl_easy_cleanup(curl);
  57. }
  58. curl_formfree(formpost);
  59. }
  60. .fi
  61. .SH DEPRECATED
  62. Deprecated in 7.56.0.
  63. .SH AVAILABILITY
  64. Added in curl 7.1
  65. .SH RETURN VALUE
  66. Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not.
  67. .SH SEE ALSO
  68. .BR CURLOPT_MIMEPOST (3),
  69. .BR CURLOPT_POST (3),
  70. .BR CURLOPT_POSTFIELDS (3),
  71. .BR curl_formadd (3),
  72. .BR curl_formfree (3),
  73. .BR curl_mime_init (3)