本文整理汇总了PHP中Goutte\Client::getCookieJar方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getCookieJar方法的具体用法?PHP Client::getCookieJar怎么用?PHP Client::getCookieJar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Goutte\Client
的用法示例。
在下文中一共展示了Client::getCookieJar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUsesCookies
public function testUsesCookies()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->getCookieJar()->set(new Cookie('test', '123'));
$crawler = $client->request('GET', 'http://www.example.com/');
$request = $this->historyPlugin->getLastRequest();
$this->assertEquals('123', $request->getCookie('test'));
}
示例2: testUsesCookiesWithCustomPort
public function testUsesCookiesWithCustomPort()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->getCookieJar()->set(new Cookie('test', '123'));
$client->request('GET', 'http://www.example.com:8000/');
$request = end($this->history)['request'];
$this->assertEquals('test=123', $request->getHeaderLine('Cookie'));
}
示例3: testFileCookieJar
public function testFileCookieJar($testSaveSessionCookie = false)
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$filename = tempnam('/tmp', 'file-cookies');
$jar = new FileCookieJar($filename, $testSaveSessionCookie);
$client->setGuzzleCookieJar($jar);
$client->getCookieJar()->set(new Cookie('test', '123'));
$client->getCookieJar()->set(new Cookie('foo', 'bar', time() + 1000));
$client->request('GET', 'http://www.example.com/');
// Call to destruct method manually to test saving cookies
$jar->__destruct();
// Make sure it wrote to the file
$contents = file_get_contents($filename);
$this->assertNotEmpty($contents);
// Load the cookieJar from the file
$cookieJarReloaded = new FileCookieJar($filename);
if ($testSaveSessionCookie) {
$this->assertEquals(2, count($cookieJarReloaded));
} else {
$this->assertEquals(1, count($cookieJarReloaded));
}
unlink($filename);
}
示例4: __construct
/**
* Constructor
*/
public function __construct()
{
$this->client = new Client();
// @FIXME without this Cookie the website serves a JavaScript only version - see known issues
$this->client->getCookieJar()->set(new Cookie('TS017d4e39', '01e0f702cf037f97362f62278696546776e7b67bec0aece008837daa4d94f77fe53d7d4c8a6fa39200300641d6aee20da460dd376505f7550bd18461d59d5c2489e7bc515b97917c372e044bb84fb8441a011139863d71d7b41a83ffdab5f7f5dc3492855c362d61bdddc129cdd1d60c4ac9a1b702547433a79abd2e4c7c9a2f9f21e7c748fe9f995fea959736b5aea76fe14d45d2181a39b1f45823787c1cd69e0457f53c'));
}