N
N
nepster-web2015-11-21 22:56:19
PHP
nepster-web, 2015-11-21 22:56:19

How to make a get request with Guzzle?

I work with the library https://github.com/guzzle/guzzle , or rather I get acquainted.
The situation is as follows:
There is an api to which the client is written in php. To send methods, I chose this library. I need to send a post request, get an access token and then work with it by sending get requests.
Sending a post request:

$client = new \GuzzleHttp\Client();
            $response = $client->request('POST', 'http://api.site.com/oauth2/user', [
                'form_params' => [
                    'username' => '***',
                    'password' => '***',
                ]
            ]);

Everything is fine here, everything works. I receive a token.
Then the problem is in the get request:
$client = new \GuzzleHttp\Client();

            $response = $client->request('GET', 'http://api.site.com/v1/groups', [
               // 'form_params' => [
                    'access_token' => $token,
               // ]
            ]);

The fact is that the access_token parameter does not fly to the server. That is, this recording option does not work.

But this one works:

$client = new \GuzzleHttp\Client();
            $response = $client->request('GET', 'http://api.site.com/v1/groups?access_token=' . $token);

Please tell me what is the problem, why does passing parameters in an array not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-11-22
@nepster-web

everything is written in the docks , but you need to run to the toaster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question