1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HTTPPOST
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_MIMEPOST (3)
9  - CURLOPT_POST (3)
10  - CURLOPT_POSTFIELDS (3)
11  - curl_formadd (3)
12  - curl_formfree (3)
13  - curl_mime_init (3)
14---
15
16# NAME
17
18CURLOPT_HTTPPOST - multipart formpost content
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPPOST,
26                          struct curl_httppost *formpost);
27~~~
28
29# DESCRIPTION
30
31**This option is deprecated.** Use CURLOPT_MIMEPOST(3) instead.
32
33Tells libcurl you want a **multipart/formdata** HTTP POST to be made and you
34instruct what data to pass on to the server in the *formpost* argument.
35Pass a pointer to a linked list of *curl_httppost* structs as parameter.
36The easiest way to create such a list, is to use curl_formadd(3) as
37documented. The data in this list must remain intact as long as the curl
38transfer is alive and is using it.
39
40Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
41You can disable this header with CURLOPT_HTTPHEADER(3).
42
43When setting CURLOPT_HTTPPOST(3), libcurl automatically sets
44CURLOPT_NOBODY(3) to 0.
45
46# DEFAULT
47
48NULL
49
50# PROTOCOLS
51
52HTTP
53
54# EXAMPLE
55
56~~~c
57int main(void)
58{
59  struct curl_httppost *formpost;
60  struct curl_httppost *lastptr;
61
62  /* Fill in the file upload field. This makes libcurl load data from
63     the given file name when curl_easy_perform() is called. */
64  curl_formadd(&formpost,
65               &lastptr,
66               CURLFORM_COPYNAME, "sendfile",
67               CURLFORM_FILE, "postit2.c",
68               CURLFORM_END);
69
70  /* Fill in the filename field */
71  curl_formadd(&formpost,
72               &lastptr,
73               CURLFORM_COPYNAME, "filename",
74               CURLFORM_COPYCONTENTS, "postit2.c",
75               CURLFORM_END);
76
77  /* Fill in the submit field too, even if this is rarely needed */
78  curl_formadd(&formpost,
79               &lastptr,
80               CURLFORM_COPYNAME, "submit",
81               CURLFORM_COPYCONTENTS, "send",
82               CURLFORM_END);
83
84  CURL *curl = curl_easy_init();
85  if(curl) {
86    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
87    curl_easy_perform(curl);
88    curl_easy_cleanup(curl);
89  }
90  curl_formfree(formpost);
91}
92~~~
93
94# AVAILABILITY
95
96As long as HTTP is enabled. Deprecated in 7.56.0.
97
98# RETURN VALUE
99
100Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not.
101