CURLOPT_MIMEPOST.md (1914B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_MIMEPOST 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_HTTPPOST (3) 9 - CURLOPT_POSTFIELDS (3) 10 - CURLOPT_PUT (3) 11 - curl_mime_init (3) 12 Protocol: 13 - HTTP 14 - SMTP 15 - IMAP 16 Added-in: 7.56.0 17 --- 18 19 # NAME 20 21 CURLOPT_MIMEPOST - send data from mime structure 22 23 # SYNOPSIS 24 25 ~~~c 26 #include <curl/curl.h> 27 28 curl_mime *mime; 29 30 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MIMEPOST, mime); 31 ~~~ 32 33 # DESCRIPTION 34 35 Pass a mime handle previously obtained from curl_mime_init(3). 36 37 This setting is supported by the HTTP protocol to post forms and by the 38 SMTP and IMAP protocols to provide the email data to send/upload. 39 40 This option is the preferred way of posting an HTTP form, replacing and 41 extending the CURLOPT_HTTPPOST(3) option. 42 43 When setting CURLOPT_MIMEPOST(3) to NULL, libcurl resets the request 44 type for HTTP to the default to disable the POST. Typically that would mean it 45 is reset to GET. Instead you should set a desired request method explicitly. 46 47 # %PROTOCOLS% 48 49 # EXAMPLE 50 51 ~~~c 52 int main(void) 53 { 54 CURL *curl = curl_easy_init(); 55 if(curl) { 56 curl_mime *multipart = curl_mime_init(curl); 57 if(multipart) { 58 curl_mimepart *part = curl_mime_addpart(multipart); 59 curl_mime_name(part, "name"); 60 curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED); 61 part = curl_mime_addpart(multipart); 62 curl_mime_name(part, "project"); 63 curl_mime_data(part, "curl", CURL_ZERO_TERMINATED); 64 part = curl_mime_addpart(multipart); 65 curl_mime_name(part, "logotype-image"); 66 curl_mime_filedata(part, "curl.png"); 67 68 /* Set the form info */ 69 curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart); 70 71 curl_easy_perform(curl); /* post away */ 72 curl_mime_free(multipart); /* free the post data */ 73 } 74 } 75 } 76 ~~~ 77 78 # %AVAILABILITY% 79 80 # RETURN VALUE 81 82 This returns CURLE_OK.