I am doing a post request to an API, When I use postman, everything works fine as expected and data is returned. When I use Guzzler, cURL or file_get_contents(), I get this long error that the incoming message has an unexpected format 'Raw'.
My search on the net suggested that I use Content-Type: application/JSON
but that doesn't solve it in my case.
This is my code:
$user =auth()->user();
$postRequest = array(
'userId' => $user->id,
'username' => $user->username,
'currency'=> 'TRY',
'nick'=>$user->username
);
$tvbetURL ="https://somewebsite.com/set_user_data";
$headers = [
'token' => '=EDMwU2N2MjM0kDNiVjYiFskljbgkjgerHUIHIOFG',
'Content-Type' => 'application/json ',
];
$client = new GuzzleClient([
'headers' => $headers
]);
$r = $client->request('POST', $tvbetURL, [
'form_params' =>$postRequest
]);
$response = $r->getBody()->getContents();
dd($response);
THE ERROR:
[2020-08-28 07:05:51] production.ERROR: Server error: POST https://somewebsite.com/set_user_data
resulted in a 500 Internal Server Error
response:
The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', ' (truncated...)
{"userId":1,"exception":"[object] (GuzzleHttp\Exception\ServerException(code: 500): Server error: POST https://somewebsite.com/set_user_data
resulted in a 500 Internal Server Error
response:
The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', ' (truncated...)
at
/opt/lampp/htdocs/projects/freelance/git/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113)
[stacktrace]
Thank you i advance.