0

成功使用爬虫登录后,我似乎无法保持身份验证。一旦我通过身份验证,我希望能够运行我的每个服务并检查接收到正确的响应。

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 返回登录后重定向到的页面。

4

1 回答 1

0

我通过删除解决了这个问题$client->followRedirects();

于 2012-07-18T20:20:14.007 回答