Zend_Http_Client 不存储 cookie
我正在使用以下代码访问受用户名/密码登录保护的页面。
//Fetch homepage
$client = new Zend_Http_Client();
$client->setCookieJar();
$client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/login.php');
//$client->setParameterPost( 'username', $_SESSION['username'] );
//$client->setParameterPost( 'password', $_SESSION['password'] );
$client->setParameterPost( 'username', '#####' );
$client->setParameterPost( 'password', '#####' );
$response = $client->request('POST');
// Now we're logged in, get private area!
$client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/index.php');
$response = $client->request('GET');
echo $response->getBody();
最后的回显总是再次返回登录屏幕(表明登录不成功)。这几乎完全是从 Zend 文档中复制的。谁能看到我做错了什么吗?
I am using the following code to access a page protected by username/password login.
//Fetch homepage
$client = new Zend_Http_Client();
$client->setCookieJar();
$client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/login.php');
//$client->setParameterPost( 'username', $_SESSION['username'] );
//$client->setParameterPost( 'password', $_SESSION['password'] );
$client->setParameterPost( 'username', '#####' );
$client->setParameterPost( 'password', '#####' );
$response = $client->request('POST');
// Now we're logged in, get private area!
$client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/index.php');
$response = $client->request('GET');
echo $response->getBody();
The echo at the end always returns the login screen again (suggesting an unsuccessful login). This is copied almost exactly from the Zend docs. Can anyone see what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该页面上的一些快速测试表明,您确实需要将提交按钮值(实际值无关紧要,它只需要存在)包含在要处理的登录的 POST 数据中。
如果您检查登录尝试的响应,您就会注意到这一点。
A quick couple of tests on that page reveal that you do indeed need to include the submit button value (the actual value is irrelevant, it just has to be present) as part of the POST data for the login to be processed.
You would have noticed this if you checked the response from the login attempt.
我昨天遇到了这个问题,查看 API 站点 。
参数 true 构造一个新的 CookieJar,没有这个参数它对我不起作用。
I had this problem yesterday, look at the API site.
The parameter true constructs a new CookieJar, without this parameter it didn't work for me.
不是一个解决方案,但是:您应该手动实例化一个
Zend_Http_CookieJar
并传递它,而不是仅使用->setCookieJar()
。这样,如果您确实收到了登录 cookie,则可以更轻松地进行调试。Not a solution, but: Instead of using just
->setCookieJar()
, you should manually instantiate aZend_Http_CookieJar
and pass that. This way you can debug more easily if you've actually received a login cookie.