1

While reading setopt function in cURL I came across CURLOPT_HTTPPOST and CURLOPT_POSTFIELDS, so just wanted to know the difference between the options

multipart/formpost(CURLOPT_HTTPPOST)

and

postfields(CURLOPT_POSTFIELDS)

Where we should use each of them?

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
zer0Id0l
  • 1,374
  • 4
  • 22
  • 36

1 Answers1

3

CURLOPT_HTTPPOST sends a multipart/formdata HTTP POST that you create with curl_formadd() and friends. Example: multi-post.c

CURLOPT_POSTFIELDS sends a "normal" POST with a content-type of x-url-form-encoded but with no encoding done by libcurl itself. Example: simplepost.c

And really, you use the one that matches what the server end wants. You can very rarely select yourself in the client-side.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
  • thank you for the examples! I also found example for POST with handling response: https://curl.se/libcurl/c/postinmemory.html – Terry Jul 08 '22 at 23:37