curl_mime_init.md (1752B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_mime_init 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_MIMEPOST (3) 9 - curl_mime_addpart (3) 10 - curl_mime_free (3) 11 - curl_mime_subparts (3) 12 Protocol: 13 - HTTP 14 - IMAP 15 - SMTP 16 Added-in: 7.56.0 17 --- 18 19 # NAME 20 21 curl_mime_init - create a mime handle 22 23 # SYNOPSIS 24 25 ~~~c 26 #include <curl/curl.h> 27 28 curl_mime *curl_mime_init(CURL *easy_handle); 29 ~~~ 30 31 # DESCRIPTION 32 33 curl_mime_init(3) creates a handle to a new empty mime structure. 34 This mime structure can be subsequently filled using the mime API, then 35 attached to some easy handle using option CURLOPT_MIMEPOST(3) within 36 a curl_easy_setopt(3) call or added as a multipart in another mime 37 handle's part using curl_mime_subparts(3). 38 39 *easy_handle* is used for part separator randomization and error 40 reporting. Since 7.87.0, it does not need to be the final target handle. 41 42 Using a mime handle is the recommended way to post an HTTP form, format and 43 send a multi-part email with SMTP or upload such an email to an IMAP server. 44 45 # %PROTOCOLS% 46 47 # EXAMPLE 48 49 ~~~c 50 int main(void) 51 { 52 CURL *easy = curl_easy_init(); 53 curl_mime *mime; 54 curl_mimepart *part; 55 56 /* Build an HTTP form with a single field named "data", */ 57 mime = curl_mime_init(easy); 58 part = curl_mime_addpart(mime); 59 curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED); 60 curl_mime_name(part, "data"); 61 62 /* Post and send it. */ 63 curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime); 64 curl_easy_setopt(easy, CURLOPT_URL, "https://example.com"); 65 curl_easy_perform(easy); 66 67 /* Clean-up. */ 68 curl_easy_cleanup(easy); 69 curl_mime_free(mime); 70 } 71 ~~~ 72 73 # %AVAILABILITY% 74 75 # RETURN VALUE 76 77 A mime struct handle, or NULL upon failure.