[英]Zend_Http_Client not storing cookies
我正在使用以下代碼訪問受用戶名/密碼登錄保護的頁面。
//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文檔中復制的。 誰能看到我在做什么錯?
在該頁面上進行的快速測試表明,您確實需要將提交按鈕值(實際值無關緊要,只需要存在)作為要處理登錄的POST數據的一部分。
$client->setParameterPost('submit', 'Login');
如果您檢查了登錄嘗試的響應,就會注意到這一點。
不是解決方案,而是:您不應該僅使用->setCookieJar()
而是應手動實例化Zend_Http_CookieJar
並將其傳遞。 這樣,如果您實際收到登錄cookie,則可以更輕松地進行調試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.