1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_MIMEPOST 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_HTTPPOST (3) 9 - CURLOPT_POSTFIELDS (3) 10 - CURLOPT_PUT (3) 11 - curl_mime_init (3) 12Protocol: 13 - HTTP 14 - SMTP 15 - IMAP 16Added-in: 7.56.0 17--- 18 19# NAME 20 21CURLOPT_MIMEPOST - send data from mime structure 22 23# SYNOPSIS 24 25~~~c 26#include <curl/curl.h> 27 28curl_mime *mime; 29 30CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MIMEPOST, mime); 31~~~ 32 33# DESCRIPTION 34 35Pass a mime handle previously obtained from curl_mime_init(3). 36 37This setting is supported by the HTTP protocol to post forms and by the 38SMTP and IMAP protocols to provide the email data to send/upload. 39 40This option is the preferred way of posting an HTTP form, replacing and 41extending the CURLOPT_HTTPPOST(3) option. 42 43When setting CURLOPT_MIMEPOST(3) to NULL, libcurl resets the request 44type for HTTP to the default to disable the POST. Typically that would mean it 45is reset to GET. Instead you should set a desired request method explicitly. 46 47# %PROTOCOLS% 48 49# EXAMPLE 50 51~~~c 52int 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 82This returns CURLE_OK. 83