CURLOPT_HTTPPOST(3)

πŸ’… CURLOPT_HTTPPOST(3) β€” multipart formpost content πŸŽ€

Okay bestie, welcome to the libcurl manual page for CURLOPT_HTTPPOST β€” it lives in the Library Functions Manual, and it is lowkey a legacy icon that still deserves its flowers. ✨


🌸 NAME 🌸

CURLOPT_HTTPPOST β€” multipart formpost content πŸ’Œ


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPPOST,
                          struct curl_httppost *formpost);

✨ DESCRIPTION ✨

Okay so first things first, bestie: this option is deprecated. Not kidding, not being dramatic β€” it literally says so. Use CURLOPT_MIMEPOST(3) instead, periodt. πŸ’…

This option tells libcurl that you want a multipart/formdata HTTP POST to happen, and you use the formpost argument to tell it what data to send to the server. You pass a pointer to a linked list of curl_httppost structs as the parameter. The easiest way to create that list is to use curl_formadd(3) as documented. 🫢

The data in this list must remain intact for as long as the curl transfer is alive and using it β€” like, don't let it ghost the transfer, okay? 😭

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable that header with CURLOPT_HTTPHEADER(3), if that's your vibe. πŸ¦‹

When you set CURLOPT_HTTPPOST(3), libcurl automatically sets CURLOPT_NOBODY(3) to 0. Not me noticing that little automatic slay. πŸ‘‘


πŸŽ€ DEFAULT πŸŽ€

NULL

Like, no formpost unless you bring one. πŸ’€


🌈 PROTOCOLS 🌈

This functionality affects http only.

Http girlies only, no cap. πŸ’–


πŸ“ EXAMPLE πŸ“

int main(void)
{
  struct curl_httppost *formpost;
  struct curl_httppost *lastptr;

  /* Fill in the file upload field. This makes libcurl load data from
     the given file name when curl_easy_perform() is called. */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "sendfile",
               CURLFORM_FILE, "postit2.c",
               CURLFORM_END);

  /* Fill in the filename field */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "filename",
               CURLFORM_COPYCONTENTS, "postit2.c",
               CURLFORM_END);

  /* Fill in the submit field too, even if this is rarely needed */
  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "submit",
               CURLFORM_COPYCONTENTS, "send",
               CURLFORM_END);

  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  curl_formfree(formpost);
}

It's giving classic C example realness, and honestly? Ate. πŸ”₯


🌸 DEPRECATED 🌸

Deprecated in 7.56.0.

Yep, she's been officially put on notice since 7.56.0. Still iconic, but use CURLOPT_MIMEPOST(3) if you're starting fresh, bestie. πŸ™ˆ


⭐ AVAILABILITY ⭐

Added in curl 7.1

Old-school legend behavior, fr fr. πŸ‘‘


πŸ’œ RETURN VALUE πŸ’œ

curl_easy_setopt(3) returns a CURLcode indicating success or error. πŸ’–

CURLE_OK (0) means everything was OK. A non-zero value means an error occurred β€” see libcurl-errors(3) for all the details.


🧚 SEE ALSO 🧚

Go read those too, iykyk. πŸ“šβœ¨


Sign-off tea β˜•: this page comes from libcurl, dated 2026-10-12, and the manual page title is CURLOPT_HTTPPOST(3). Stay multipart, stay hydrated, and remember: deprecated does not mean forgotten. πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from