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