CURLOPT_MIMEPOST.3 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. .\" generated by cd2nroff 0.1 from CURLOPT_MIMEPOST.md
  2. .TH CURLOPT_MIMEPOST 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_MIMEPOST \- send data from mime structure
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. curl_mime *mime;
  9. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MIMEPOST, mime);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a mime handle previously obtained from \fIcurl_mime_init(3)\fP.
  13. This setting is supported by the HTTP protocol to post forms and by the
  14. SMTP and IMAP protocols to provide the email data to send/upload.
  15. This option is the preferred way of posting an HTTP form, replacing and
  16. extending the \fICURLOPT_HTTPPOST(3)\fP option.
  17. When setting \fICURLOPT_MIMEPOST(3)\fP to NULL, libcurl resets the request
  18. type for HTTP to the default to disable the POST. Typically that would mean it
  19. is reset to GET. Instead you should set a desired request method explicitly.
  20. .SH PROTOCOLS
  21. This functionality affects http, imap and smtp
  22. .SH EXAMPLE
  23. .nf
  24. int main(void)
  25. {
  26. CURL *curl = curl_easy_init();
  27. if(curl) {
  28. curl_mime *multipart = curl_mime_init(curl);
  29. if(multipart) {
  30. curl_mimepart *part = curl_mime_addpart(multipart);
  31. curl_mime_name(part, "name");
  32. curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED);
  33. part = curl_mime_addpart(multipart);
  34. curl_mime_name(part, "project");
  35. curl_mime_data(part, "curl", CURL_ZERO_TERMINATED);
  36. part = curl_mime_addpart(multipart);
  37. curl_mime_name(part, "logotype-image");
  38. curl_mime_filedata(part, "curl.png");
  39. /* Set the form info */
  40. curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart);
  41. curl_easy_perform(curl); /* post away! */
  42. curl_mime_free(multipart); /* free the post data */
  43. }
  44. }
  45. }
  46. .fi
  47. .SH AVAILABILITY
  48. Added in curl 7.56.0
  49. .SH RETURN VALUE
  50. This returns CURLE_OK.
  51. .SH SEE ALSO
  52. .BR CURLOPT_HTTPPOST (3),
  53. .BR CURLOPT_POSTFIELDS (3),
  54. .BR CURLOPT_PUT (3),
  55. .BR curl_mime_init (3)