当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::setDefaultHeaders方法代码示例

本文整理汇总了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);
 }
开发者ID:AlucardleVash,项目名称:tech.vg.no-1812,代码行数:15,代码来源:FeatureContext.php

示例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);
 }
开发者ID:ASP96,项目名称:imbo,代码行数:12,代码来源:RESTContext.php

示例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;
 }
开发者ID:jedibc,项目名称:phpseries,代码行数:14,代码来源:Client.php

示例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.");
     }
 }
开发者ID:johannez,项目名称:chargify,代码行数:18,代码来源:Factory.php

示例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;
 }
开发者ID:anime-db,项目名称:world-art-filler-bundle,代码行数:23,代码来源:Browser.php

示例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;
     }
 }
开发者ID:onpaws,项目名称:honeybadger-php,代码行数:24,代码来源:Sender.php

示例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;
 }
开发者ID:carlesgutierrez,项目名称:libreobjet.org,代码行数:20,代码来源:ClientTest.php

示例8: testValidatesDefaultHeaders

 /**
  * @covers Guzzle\Http\Client::setDefaultHeaders
  * @expectedException InvalidArgumentException
  */
 public function testValidatesDefaultHeaders()
 {
     $client = new Client();
     $client->setDefaultHeaders('foo');
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:9,代码来源:ClientTest.php

示例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'));
 }
开发者ID:aoemedia,项目名称:searchperience-api-client,代码行数:8,代码来源:AbstractRestBackend.php


注:本文中的Guzzle\Http\Client::setDefaultHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。