xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_HTTPPOST.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_HTTPPOST
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerProtocol:
8*6236dae4SAndroid Build Coastguard Worker  - HTTP
9*6236dae4SAndroid Build Coastguard WorkerSee-also:
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_MIMEPOST (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_POST (3)
12*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_POSTFIELDS (3)
13*6236dae4SAndroid Build Coastguard Worker  - curl_formadd (3)
14*6236dae4SAndroid Build Coastguard Worker  - curl_formfree (3)
15*6236dae4SAndroid Build Coastguard Worker  - curl_mime_init (3)
16*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1
17*6236dae4SAndroid Build Coastguard Worker---
18*6236dae4SAndroid Build Coastguard Worker
19*6236dae4SAndroid Build Coastguard Worker# NAME
20*6236dae4SAndroid Build Coastguard Worker
21*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HTTPPOST - multipart formpost content
22*6236dae4SAndroid Build Coastguard Worker
23*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard Worker~~~c
26*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPPOST,
29*6236dae4SAndroid Build Coastguard Worker                          struct curl_httppost *formpost);
30*6236dae4SAndroid Build Coastguard Worker~~~
31*6236dae4SAndroid Build Coastguard Worker
32*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard Worker**This option is deprecated.** Use CURLOPT_MIMEPOST(3) instead.
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard WorkerTells libcurl you want a **multipart/formdata** HTTP POST to be made and you
37*6236dae4SAndroid Build Coastguard Workerinstruct what data to pass on to the server in the *formpost* argument.
38*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a linked list of *curl_httppost* structs as parameter.
39*6236dae4SAndroid Build Coastguard WorkerThe easiest way to create such a list, is to use curl_formadd(3) as
40*6236dae4SAndroid Build Coastguard Workerdocumented. The data in this list must remain intact as long as the curl
41*6236dae4SAndroid Build Coastguard Workertransfer is alive and is using it.
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard WorkerUsing POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
44*6236dae4SAndroid Build Coastguard WorkerYou can disable this header with CURLOPT_HTTPHEADER(3).
45*6236dae4SAndroid Build Coastguard Worker
46*6236dae4SAndroid Build Coastguard WorkerWhen setting CURLOPT_HTTPPOST(3), libcurl automatically sets
47*6236dae4SAndroid Build Coastguard WorkerCURLOPT_NOBODY(3) to 0.
48*6236dae4SAndroid Build Coastguard Worker
49*6236dae4SAndroid Build Coastguard Worker# DEFAULT
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard WorkerNULL
52*6236dae4SAndroid Build Coastguard Worker
53*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard Worker~~~c
58*6236dae4SAndroid Build Coastguard Workerint main(void)
59*6236dae4SAndroid Build Coastguard Worker{
60*6236dae4SAndroid Build Coastguard Worker  struct curl_httppost *formpost;
61*6236dae4SAndroid Build Coastguard Worker  struct curl_httppost *lastptr;
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker  /* Fill in the file upload field. This makes libcurl load data from
64*6236dae4SAndroid Build Coastguard Worker     the given file name when curl_easy_perform() is called. */
65*6236dae4SAndroid Build Coastguard Worker  curl_formadd(&formpost,
66*6236dae4SAndroid Build Coastguard Worker               &lastptr,
67*6236dae4SAndroid Build Coastguard Worker               CURLFORM_COPYNAME, "sendfile",
68*6236dae4SAndroid Build Coastguard Worker               CURLFORM_FILE, "postit2.c",
69*6236dae4SAndroid Build Coastguard Worker               CURLFORM_END);
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard Worker  /* Fill in the filename field */
72*6236dae4SAndroid Build Coastguard Worker  curl_formadd(&formpost,
73*6236dae4SAndroid Build Coastguard Worker               &lastptr,
74*6236dae4SAndroid Build Coastguard Worker               CURLFORM_COPYNAME, "filename",
75*6236dae4SAndroid Build Coastguard Worker               CURLFORM_COPYCONTENTS, "postit2.c",
76*6236dae4SAndroid Build Coastguard Worker               CURLFORM_END);
77*6236dae4SAndroid Build Coastguard Worker
78*6236dae4SAndroid Build Coastguard Worker  /* Fill in the submit field too, even if this is rarely needed */
79*6236dae4SAndroid Build Coastguard Worker  curl_formadd(&formpost,
80*6236dae4SAndroid Build Coastguard Worker               &lastptr,
81*6236dae4SAndroid Build Coastguard Worker               CURLFORM_COPYNAME, "submit",
82*6236dae4SAndroid Build Coastguard Worker               CURLFORM_COPYCONTENTS, "send",
83*6236dae4SAndroid Build Coastguard Worker               CURLFORM_END);
84*6236dae4SAndroid Build Coastguard Worker
85*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
86*6236dae4SAndroid Build Coastguard Worker  if(curl) {
87*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
88*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
89*6236dae4SAndroid Build Coastguard Worker    curl_easy_cleanup(curl);
90*6236dae4SAndroid Build Coastguard Worker  }
91*6236dae4SAndroid Build Coastguard Worker  curl_formfree(formpost);
92*6236dae4SAndroid Build Coastguard Worker}
93*6236dae4SAndroid Build Coastguard Worker~~~
94*6236dae4SAndroid Build Coastguard Worker
95*6236dae4SAndroid Build Coastguard Worker# DEPRECATED
96*6236dae4SAndroid Build Coastguard Worker
97*6236dae4SAndroid Build Coastguard WorkerDeprecated in 7.56.0.
98*6236dae4SAndroid Build Coastguard Worker
99*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
100*6236dae4SAndroid Build Coastguard Worker
101*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
102*6236dae4SAndroid Build Coastguard Worker
103*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not.
104