如何使用guzzlehttp登录使用登录凭据的应用程序?

时间:2017-03-01 12:25:23

标签: php guzzle6 guzzlehttp

如何使用guzzlehttp登录使用登录凭据的应用程序?提前谢谢。

1 个答案:

答案 0 :(得分:0)

登录您的应用程序应该像使用正确的凭据对正确的端点发布请求一样简单。

例如来自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'
        ]
    ] ]);

然而,应用程序很可能使用cookie来维护状态。默认情况下,Guzzle不存储cookie,但您可以使用cookie插件启用此行为。 http://guzzle3.readthedocs.io/plugins/cookie-plugin.html

启用此功能后,您只需要初始请求即可登录应用程序并启动会话。您的第二次通话应该以登录用户身份进行。

相关问题