CURLOPT_HTTPPOST.md (2573B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_HTTPPOST 5 Section: 3 6 Source: libcurl 7 Protocol: 8 - HTTP 9 See-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 Added-in: 7.1 17 --- 18 19 # NAME 20 21 CURLOPT_HTTPPOST - multipart formpost content 22 23 # SYNOPSIS 24 25 ~~~c 26 #include <curl/curl.h> 27 28 CURLcode 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 36 Tells libcurl you want a **multipart/formdata** HTTP POST to be made and you 37 instruct what data to pass on to the server in the *formpost* argument. 38 Pass a pointer to a linked list of *curl_httppost* structs as parameter. 39 The easiest way to create such a list, is to use curl_formadd(3) as 40 documented. The data in this list must remain intact as long as the curl 41 transfer is alive and is using it. 42 43 Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. 44 You can disable this header with CURLOPT_HTTPHEADER(3). 45 46 When setting CURLOPT_HTTPPOST(3), libcurl automatically sets 47 CURLOPT_NOBODY(3) to 0. 48 49 # DEFAULT 50 51 NULL 52 53 # %PROTOCOLS% 54 55 # EXAMPLE 56 57 ~~~c 58 int 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 97 Deprecated in 7.56.0. 98 99 # %AVAILABILITY% 100 101 # RETURN VALUE 102 103 curl_easy_setopt(3) returns a CURLcode indicating success or error. 104 105 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 106 libcurl-errors(3).