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