I tried to send JSON request from me server like this :
public function subscribe() {
$arrData = array(
'name' => $name,
'user_id' => $user_id,
'merchant_reference' => $merchant_reference
);
$ch = curl_init(env('MY_API'));
# Setup request to send json via POST.
$data = json_encode($arrData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
}
And when I call this function from the browser I get error 415,
But when I call it from Postman it work's fine and return the right response.
Any ideas?
$arrDatadefined?'Accept: application/json',in header and test, and# Setup request to send json via POST.how?$arrDatadoes not exist in thesubscribemethod's scope.Accept: application/jsonheader but still getting the same error415 Unsupported Media Typecurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));?