CURLOPT_POST vs. CURLOPT_POSTFIELDS: Is CURLOPT_POST option required? CURLOPT_POST vs. CURLOPT_POSTFIELDS: Is CURLOPT_POST option required? curl curl

CURLOPT_POST vs. CURLOPT_POSTFIELDS: Is CURLOPT_POST option required?


You are correct. CURLOPT_POSTFIELDS implies CURLOPT_POST. You don't need to use CURLOPT_POST while using CURLOPT_POSTFIELDS. The request method will always be set to POST in this case.

Note that this is in your case as long as you want it to be a POST request.

If you don't want to be it a POST request but set CURLOPT_POSTFIELDS, please see this related Q&A:


For future reference the API document say this about CURLOPT_POST


Summary:

A true parameter tells the library to do a regular HTTP post. This will also make the library use the a "Content-Type: application/x-www-form-urlencoded" header. (This is by far the most commonly used POST method).

Use the CURLOPT_POSTFIELDS option to specify what data to post and CURLOPT_POSTFIELDSIZE to set the data size. Optionally, you can provide data to POST using the CURLOPT_READFUNCTION and CURLOPT_READDATA options.

You can override the default POST Content-Type: header by setting your own with CURLOPT_HTTPHEADER.

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER as usual.

If you use POST to a HTTP 1.1 server, you can send data without knowing the size before starting the POST if you use chunked encoding. You enable this by adding a header like "Transfer-Encoding: chunked" with CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, you must specify the size in the request.

if you have issued a POST request and want to make a HEAD or GET instead, you must explicitly pick the new request type using CURLOPT_NOBODY or CURLOPT_HTTPGET or similar.


I'm testing right now whether setting the CURLOPT_POST to try will override my CURLOPT_HTTPHEADER, "Content-Type: application/json; charset=utf-8" setting.