Is it possible to pass an array of data for GET
request in GuzzlePHP Client?
I've found nothing in documentation and on Stack Overflow.
i.e this does not work as I expect:
// first level of this array is refered as
// request settings: headers, redirects, etc.
$array = [
'this will be rendered as request settings',
'data' => [
'var1' => 'value1',
'var4' => 'value4',
],
];
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', '/redirect/3', $array);
Edit: For all those who can't understand the problem:
GET parameters are not passed in this request, thus I only get this URL structure:
http://host/redirect/3
Expected:
http://host/redirect/3?var1=value1&var4=value4
Found it finally. Settings key is query
If anyone else needs it:
$params = [
'var1' => 'value1',
'var4' => 'value4',
];
$client->request('GET', '/redirect/3', [
'query' => $params
]);
This finally transforms the URL of my request into:
/redirect/3?var1=value1&var4=value4
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments