I am using the Email on Acid API.
While sending POST
requests to the endpoint http://sandbox.emailonacid.com/v4/GetClientList
through PHP Curl, I tried the following alternatives :
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST")
curl_setopt($ch, CURLOPT_POST, 1);
The first option works, but the second option returns an HTTP 400 Bad Request.
Can anyone explain the behavior?
This option can be used to specify the request: HTTP. Instead of GET or HEAD when performing HTTP based requests. This is particularly useful, for example, for performing an HTTP DELETE request.
CURLOPT_POST. true to do a regular HTTP POST. This POST is the normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.
The curl_setopt() function will set options for a CURL session identified by the ch parameter. The option parameter is the option you want to set, and the value is the value of the option given by the option. The value should be a long for the following options (specified in the option parameter):
By default CURLOPT_POST will perform a regular POST request using a Content-Type
header of "application/x-www-form-urlencoded" which is typically the kind used when submitting HTML forms.
The API you're consuming has restricted Accept
headers for application/json
or application/xml
depending on whether your sending a JSON or XML payload.
You can override the default Content-Type
for a regular POST header using:
$headers = ['Content-Type: application/json'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With