Reputation: 1
How to login into an application with login credentials using guzzlehttp?
Upvotes: -3
Views: 124
Reputation: 1404
Login into your application should be as straightforward as doing a post request to the correct endpoint with correct credentials.
eg from the docs at http://docs.guzzlephp.org/en/latest/quickstart.html
$response = $client->request('POST', 'http://httpbin.org/post', [
'form_params' => [
'field_name' => 'abc',
'other_field' => '123',
'nested_field' => [
'nested' => 'hello'
]
] ]);
However most likely the application is using cookies to maintain state. By default Guzzle doesn't store cookies, but you can enable this behaviour with the cookie plugin. http://guzzle3.readthedocs.io/plugins/cookie-plugin.html
Once this is enabled you just need an initial request to login to the application and initiate the session. Your second call should happen as a logged in user.
Upvotes: 0