如何获得过去登录屏幕上Guzzle电话 [英] How to get past login screen on Guzzle call

查看:138
本文介绍了如何获得过去登录屏幕上Guzzle电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用cURL将信息发送到外部网站。我在我的Laravel应用程序上设置了Guzzle。我有基本设置,但根据网站的文档,有一个操作,需要的用户名和密码。

I have to send information to an external website using cURL. I set up Guzzle on my Laravel application. I have the basics set up, but according to the documentation of the website, there is an action that's required for the username and password. How can I pass the 'action' along with the credentials needed to log in and get access?

网站声明:

curl [-k] -dump-header< header_file> -Faction = login-Fusername =< username>-Fpassword =< password>https://< website_URL>

我的控制器

    $client = new \GuzzleHttp\Client();

    $response = $client->get('http://website.com/page/login/', array(
        'auth' => array('username', 'password')
    ));

    $xml = $response;
    echo $xml;

网站将加载 echo 但它只会拉起登录屏幕。

The website will load on the echo, but it will only pull up the login screen. I need those credentials to bypass the login screen (with a successful login) to get to the portion of information I need for cURL.

推荐答案

我需要这些凭据绕过登录屏幕(成功登录)才能获得我需要的cURL部分。 p> curl -F 提交POST请求,而不是GET请求。因此,您需要相应地修改代码,例如

curl -F submits a POST request instead of a GET request. So you'll need to modify your code accordingly, something like

$client = new \GuzzleHttp\Client();

$response = $client->post('http://website.com/page/login/', [
    'body' => [
        'username' => $username,
        'password' => $password,
        'action' => 'login'
    ],
    'cookies' => true
]
);

$xml = $response;
echo $xml;

查看 http://guzzle.readthedocs.org/en/latest/quickstart.html#post-requests http://curl.haxx.se/docs/manpage.html#-F

编辑:

只需添加 ['cookies'=> true] ,以便使用与此 GuzzleHttp \Client()相关联的auth cookie。 http://guzzle.readthedocs.org/en/latest/clients.html#cookies

Just add ['cookies' => true] to requests in order to use the auth cookie associated with this GuzzleHttp\Client(). http://guzzle.readthedocs.org/en/latest/clients.html#cookies

$response2 = $client->get('http://website.com/otherpage/', ['cookies' => true]);

这篇关于如何获得过去登录屏幕上Guzzle电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆