0
成功使用爬蟲登錄後,我似乎無法保持身份驗證。一旦我通過身份驗證,我希望能夠貫穿每個服務並檢查接收到的正確響應。Symfony功能測試 - 無法保持登錄狀態
public function testGetClientsAction()
{
$client = static::createClient();
$client->followRedirects();
$cookie = new Cookie('locale2', 'en', time() + 3600 * 24 * 7, '/', null, false, false);
$client->getCookieJar()->set($cookie);
// Visit user login page and login
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('login')->form();
$crawler = $client->submit($form, array('_username' => 'greg', '_password' => 'greg'));
$client->insulate();
$client->request(
'GET',
'/clients/12345',
array(),
array(),
array('X-Requested-With' => "XMLHttpRequest")
);
print_r($client->getResponse()->getContent());
die();
}
print_r返回重定向到登錄後的頁面。