I am trying to make a Curl request on PHP, but it is giving an error for missing fields, even though it works on Shell.
Shell:
<code>curl --request POST --data -k '{"district":"sandbox"}' --location https://dev.myurl.ca/api/update.php?key=abc
</code>
<code>curl --request POST --data -k '{"district":"sandbox"}' --location https://dev.myurl.ca/api/update.php?key=abc
</code>
curl --request POST --data -k '{"district":"sandbox"}' --location https://dev.myurl.ca/api/update.php?key=abc
Returns the result successfully
PHP:
<code>$payload = [
'district' => 'sandbox',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://dev.myurl.ca/api/update.php?key=abc");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
</code>
<code>$payload = [
'district' => 'sandbox',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://dev.myurl.ca/api/update.php?key=abc");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
</code>
$payload = [
'district' => 'sandbox',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://dev.myurl.ca/api/update.php?key=abc");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
returns
<code>{"errormessage":"missing parameter- district","status":"fail"}
</code>
<code>{"errormessage":"missing parameter- district","status":"fail"}
</code>
{"errormessage":"missing parameter- district","status":"fail"}
What am I doing wrong here?
Thanks.
1