Skip to content

Instantly share code, notes, and snippets.

@achmadfatoni
Created August 29, 2017 09:21
Show Gist options
  • Save achmadfatoni/8c67cc430f4de18926c42abf24aedbc1 to your computer and use it in GitHub Desktop.
Save achmadfatoni/8c67cc430f4de18926c42abf24aedbc1 to your computer and use it in GitHub Desktop.
Guzzle Raw POST request
$client = new Client();
$array = [];
$res = $client->request('POST', $url, [
'body' => json_encode($array),
'headers' => [
'Content-Type' => 'application/json',
]
]);
@faisal3956
Copy link

thanks help alot

@KyawSoeKhaing777
Copy link

Thanks @achmadfatoni, It works for me.

@SamuelMaculuve
Copy link

Thanks work for me.

@bistoco
Copy link

bistoco commented Mar 1, 2025

First of all, thanks.
For me it was expecting --data-raw, but instead of 'Content-Type' => 'application/json, was expecting form-data like 'Content-Type' => 'application/x-www-form-urlencoded',

$res = $client->request('POST', $url,
        [
            'body' => 'field=value',
            'headers' => [
                'Content-Type'  => 'application/x-www-form-urlencoded',
            ]
        ]
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment