Pass array for GET data in GuzzlePHP

Zlatan Omerović

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
Zlatan Omerović

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot pass returned data from $.get to variable or array in JavaScript

From Dev

How to get join table data and pass inside array in php

From Dev

How to pass array of data to controller?

From Dev

C# Pass data to array

From Dev

how to pass array in data (ajax)

From Dev

GuzzlePHP mock response content

From Dev

How to pass and get array as an argument to shell script

From Dev

How to pass values of $_GET array to new URL?

From Dev

how to pass get method method in curl array

From Dev

How to pass list argument to TCL array get?

From Dev

Pass form value to function to get array value

From Dev

Pass array and/or object data between Polymer elements

From Dev

How to pass a MySql Hierarchical data to a array in PHP?

From Dev

how to pass an array of data through cURL in php?

From Dev

Pass php variable/array data to angular js

From Dev

Pass array and/or object data between Polymer elements

From Dev

How to pass a MySql Hierarchical data to a array in PHP?

From Dev

knockout - pass child array with viewmodel data

From Dev

How to pass a simple array data in ngStorage,$localstorage?

From Dev

pass form values into my php data array

From Dev

Store data from these inputs in an array to pass in formdata

From Dev

How to pass the array of input data to Ajax function?

From Dev

Get data from ajax and pass it to a popup

From Dev

SQLite get all data and pass it to an Adapter

From Dev

Could we pass GET data to css?

From Dev

How to pass a C struct to Python to get data?

From Dev

Get data from a table line and pass it to a form

From Dev

Get card data and pass to intent when clicked

From Dev

Could we pass GET data to css?

Related Related

HotTag

Archive