成功使用爬虫登录后,我似乎无法保持身份验证。一旦我通过了身份验证,我希望能够运行我的每个服务,并检查接收正确的响应。
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在登录后返回重定向到的页面。
发布于 2012-07-19 04:20:14
我通过删除$client->followRedirects();解决了这个问题
https://stackoverflow.com/questions/11548969
复制相似问题