本文整理汇总了PHP中Guzzle\Http\Client::setDefaultHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setDefaultHeaders方法的具体用法?PHP Client::setDefaultHeaders怎么用?PHP Client::setDefaultHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::setDefaultHeaders方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Class constructor
*
* @param array $parameters Context parameters
*/
public function __construct(array $parameters)
{
$this->params = $parameters;
$this->client = new Client($this->params['url']);
$defaultHeaders = array('X-Test-Session-Id' => self::$testSessionId);
if ($this->params['enableCodeCoverage']) {
$defaultHeaders['X-Enable-Coverage'] = 1;
}
$this->client->setDefaultHeaders($defaultHeaders);
}
示例2: createClient
/**
* Create a new HTTP client
*/
private function createClient()
{
$this->client = new Client($this->params['url']);
$defaultHeaders = array('X-Test-Session-Id' => self::$testSessionId);
if ($this->params['enableCodeCoverage']) {
$defaultHeaders['X-Enable-Coverage'] = 1;
}
$this->client->setDefaultHeaders($defaultHeaders);
}
示例3: getGuzzleClient
/**
* @return GuzzleClient
*/
protected function getGuzzleClient()
{
if (is_null($this->guzzleClient)) {
$this->guzzleClient = new GuzzleClient($this->host);
$this->guzzleClient->setDefaultHeaders(array('User-Agent' => $this->userAgent));
if (!is_null($this->logger)) {
$this->guzzleClient->addSubscriber(new LogPlugin(new MonologLogAdapter($this->logger), MessageFormatter::DEBUG_FORMAT));
}
}
return $this->guzzleClient;
}
示例4: build
public static function build($type, $domain, $api_key)
{
// Get the base url for all the connections.
$base_url = sprintf('https://%s.chargify.com', $domain);
// Set the response format through the header.
$header = array('Content-Type' => 'application/json', 'Accept' => 'application/json');
// Add the same basic authentication to all requests.
$basicAuth = new CurlAuthPlugin($api_key, 'x');
$client = new Client($base_url);
$client->addSubscriber($basicAuth);
$client->setDefaultHeaders($header);
$class_name = 'Chargify\\Controller\\' . ucfirst($type);
if (class_exists($class_name)) {
return new $class_name($client);
} else {
throw new Exception("Invalid controller type given.");
}
}
示例5: getBrowser
/**
* Get HTTP browser
*
* @param \Guzzle\Http\Client
*/
protected function getBrowser()
{
if (!$this->browser instanceof Client) {
$this->browser = new Client($this->host);
// try to set User-Agent from original request
$user_agent = self::DEFAULT_USER_AGENT;
if ($this->request) {
$user_agent = $this->request->server->get('HTTP_USER_AGENT', self::DEFAULT_USER_AGENT);
}
$this->browser->setDefaultHeaders(['User-Agent' => $user_agent]);
// configure browser client
$this->browser->setDefaultOption('timeout', $this->timeout);
if ($this->proxy_list) {
$this->browser->setDefaultOption('proxy', $this->proxy_list[array_rand($this->proxy_list)]);
}
}
return $this->browser;
}
示例6: setup_http_client
private function setup_http_client()
{
// Fetch a copy of the configuration.
$config = Honeybadger::$config;
$options = array('curl.options' => array('CURLOPT_CONNECTTIMEOUT' => $config->http_open_timeout, 'CURLOPT_TIMEOUT' => $config->http_read_timeout, 'CURLOPT_AUTOREFERER' => TRUE, 'CURLOPT_FOLLOWLOCATION' => TRUE, 'CURLOPT_MAXREDIRS' => 10));
if ($config->proxy_host) {
$options['curl.options']['CURLOPT_HTTPPROXYTUNNEL'] = TRUE;
$options['curl.options']['CURLOPT_PROXY'] = $config->proxy_host;
$options['curl.options']['CURLOPT_PROXYPORT'] = $config->proxy_user . ':' . $config->proxy_pass;
}
if ($config->is_secure()) {
$options['ssl.certificate_authority'] = $config->certificate_authority;
}
try {
$client = new Client($config->base_url(), $options);
$client->setDefaultHeaders(self::$default_headers);
$client->setUserAgent($this->user_agent());
return $client;
} catch (Exception $e) {
// $this->log(Logger::ERROR, '['.__CLASS__.'::setup_http_client] Failure initializing the request client. Error: [ '.$e->getCode().' ] '.$e->getMessage());
// Rethrow the exception
throw $e;
}
}
示例7: testAllowsDefaultHeaders
public function testAllowsDefaultHeaders()
{
Version::$emitWarnings = false;
$default = array('X-Test' => 'Hi!');
$other = array('X-Other' => 'Foo');
$client = new Client();
$client->setDefaultHeaders($default);
$this->assertEquals($default, $client->getDefaultHeaders()->getAll());
$client->setDefaultHeaders(new Collection($default));
$this->assertEquals($default, $client->getDefaultHeaders()->getAll());
$request = $client->createRequest('GET', null, $other);
$this->assertEquals('Hi!', $request->getHeader('X-Test'));
$this->assertEquals('Foo', $request->getHeader('X-Other'));
$request = $client->createRequest('GET', null, new Collection($other));
$this->assertEquals('Hi!', $request->getHeader('X-Test'));
$this->assertEquals('Foo', $request->getHeader('X-Other'));
$request = $client->createRequest('GET');
$this->assertEquals('Hi!', $request->getHeader('X-Test'));
Version::$emitWarnings = true;
}
示例8: testValidatesDefaultHeaders
/**
* @covers Guzzle\Http\Client::setDefaultHeaders
* @expectedException InvalidArgumentException
*/
public function testValidatesDefaultHeaders()
{
$client = new Client();
$client->setDefaultHeaders('foo');
}
示例9: injectRestClient
/**
* @param \Guzzle\Http\Client $restClient
* @return void
*/
public function injectRestClient(\Guzzle\Http\Client $restClient)
{
$this->restClient = $restClient->setDefaultHeaders(array('User-Agent' => 'Searchperience-API-Client version: ' . \Searchperience\Common\Version::Version, 'Accepts' => 'application/searchperienceproduct+xml,application/xml,text/xml'));
}