Cristian Gonzalez
Cristian Gonzalez

Reputation: 163

PHP GuzzleHttp . How to send a json post?

I have this post:

{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}

And i'm trying to send it like this on Guzzle 6.0+

'headers' => [
                'Content-Type' => 'application/json',
                'Referer' => 'https://www.rituals.com/es-es/stores'],
'body' => '{"latitude":"","longitude":"","countryCode":"ES","filterPostalCode":"","filterCity":"","filterCountryCode":"ES","searchText":"","nextPageToken":0,"storeType":"normal","checkStoreAvailability":false}']

But it's not working, any way to send everything without formating it like I posted? thanks!

Upvotes: 0

Views: 134

Answers (1)

Volkan Yılmaz
Volkan Yılmaz

Reputation: 639

First of create Client object

$client = new Client([
     'http_errors' => false,
     'verify'      => false,
]);

And then your request with params

$response = $client->request($requestMethod, $url, array_merge(
    ['json' => $body],
    ['headers' => $headers]
));

Upvotes: 1

Related Questions