本文整理汇总了PHP中Goutte\Client::setAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setAuth方法的具体用法?PHP Client::setAuth怎么用?PHP Client::setAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Goutte\Client
的用法示例。
在下文中一共展示了Client::setAuth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getXML
private function getXML($query, $mal = true, $account = null)
{
if ($mal) {
$client = new Client();
if (empty($account)) {
$client->setAuth(ConnectDetails::$mal_username, ConnectDetails::$mal_password);
} else {
$client->setAuth($account["username"], $account["password"]);
}
$response = $client->request('GET', $this->mal_base_url . '' . $query);
try {
$xml = simplexml_load_string($response->html());
return $xml;
} catch (Exception $e) {
$e->getMessage();
}
}
return null;
}
示例2: testUsesAuth
public function testUsesAuth()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
$crawler = $client->request('GET', 'http://www.example.com/');
$request = $this->historyPlugin->getLastRequest();
$this->assertEquals('me', $request->getUsername());
$this->assertEquals('**', $request->getPassword());
}
示例3: testRestart
public function testRestart()
{
$client = new Client();
$client->setHeader('X-Test', 'test');
$client->setAuth('foo', 'bar');
$headersReflectionProperty = new \ReflectionProperty('Goutte\\Client', 'headers');
$headersReflectionProperty->setAccessible(true);
$this->assertEquals(array('X-Test' => 'test'), $headersReflectionProperty->getValue($client));
$authReflectionProperty = new \ReflectionProperty('Goutte\\Client', 'auth');
$authReflectionProperty->setAccessible(true);
$this->assertEquals(array('foo', 'bar', 'basic'), $authReflectionProperty->getValue($client));
$client->restart();
$this->assertEquals([], $headersReflectionProperty->getValue($client));
$this->assertNull($authReflectionProperty->getValue($client));
}
示例4: testResetsAuth
public function testResetsAuth()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
$client->resetAuth();
$crawler = $client->request('GET', 'http://www.example.com/');
$request = $this->history->getLastRequest();
$this->assertNull($request->getConfig()->get('auth')[0]);
$this->assertNull($request->getConfig()->get('auth')[1]);
}
示例5: testResetsAuth
public function testResetsAuth()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
$client->resetAuth();
$client->request('GET', 'http://www.example.com/');
$request = end($this->history)['request'];
$this->assertEquals('', $request->getHeaderLine('authorization'));
}