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


PHP Request::setHeader方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Request::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setHeader方法的具体用法?PHP Request::setHeader怎么用?PHP Request::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Request的用法示例。


在下文中一共展示了Request::setHeader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addAuthenticationHeaders

 /**
  * Sign the current request for write operations
  *
  * @param Request $request The current request
  */
 private function addAuthenticationHeaders(Request $request)
 {
     $client = $request->getClient();
     // Get a GMT/UTC timestamp
     $timestamp = gmdate('Y-m-d\\TH:i:s\\Z');
     // Build the data to base the hash on
     $data = $request->getMethod() . '|' . $request->getUrl() . '|' . $client->getConfig('publicKey') . '|' . $timestamp;
     // Generate signature
     $signature = hash_hmac('sha256', $data, $client->getConfig('privateKey'));
     // Add relevant request headers (overwriting once that might already exist)
     $request->setHeader('X-Imbo-Authenticate-Signature', $signature);
     $request->setHeader('X-Imbo-Authenticate-Timestamp', $timestamp);
 }
开发者ID:sgulseth,项目名称:imboclient-php,代码行数:18,代码来源:Authenticate.php

示例2: signRequest

 /**
  * @param \Guzzle\Http\Message\Request $request
  */
 public function signRequest(Request $request)
 {
     $requestWrapper = new RequestWrapper($request);
     if (!$request->hasHeader('Date')) {
         $time = new \DateTime();
         $time->setTimezone(new \DateTimeZone('GMT'));
         $request->setHeader('Date', $time->format(ClientInterface::HTTP_DATE));
     }
     if (!$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', $this->defaultContentType);
     }
     $authorization = $this->requestSigner->getAuthorization($requestWrapper, $this->id, $this->secretKey);
     $request->setHeader('Authorization', $authorization);
 }
开发者ID:acquia,项目名称:hmac-request,代码行数:17,代码来源:HmacAuthPlugin.php

示例3: testCatchesAllHostHeaderChanges

 /**
  * @covers Guzzle\Http\Message\Request::changedHeader
  * @covers Guzzle\Http\Message\Request::setHeader
  */
 public function testCatchesAllHostHeaderChanges()
 {
     // Tests setting using headers
     $this->request->setHeader('Host', 'www.abc.com');
     $this->assertEquals('www.abc.com', $this->request->getHost());
     $this->assertEquals('www.abc.com:8124', $this->request->getHeader('Host'));
     $this->assertEquals(8124, $this->request->getPort());
     // Tests setting using setHost()
     $this->request->setHost('abc.com');
     $this->assertEquals('abc.com', $this->request->getHost());
     $this->assertEquals('abc.com:8124', $this->request->getHeader('Host'));
     $this->assertEquals(8124, $this->request->getPort());
     // Tests setting with a port
     $this->request->setHost('abc.com:8081');
     $this->assertEquals('abc.com', $this->request->getHost());
     $this->assertEquals('abc.com:8081', $this->request->getHeader('Host'));
     $this->assertEquals(8081, $this->request->getPort());
     // Tests setting with a port using the Host header
     $this->request->setHeader('Host', 'solr.com:8983');
     $this->assertEquals('solr.com', $this->request->getHost());
     $this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
     $this->assertEquals(8983, $this->request->getPort());
     // Tests setting with an inferred 443 port using the Host header
     $this->request->setScheme('https');
     $this->request->setHeader('Host', 'solr.com');
     $this->assertEquals('solr.com', $this->request->getHost());
     $this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
     $this->assertEquals(8983, $this->request->getPort());
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:33,代码来源:RequestTest.php

示例4: testHoldsCookies

 public function testHoldsCookies()
 {
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Multiple cookies by setting the Cookie header
     $this->request->setHeader('Cookie', '__utma=1.638370270.1344367610.1374365610.1944450276.2; __utmz=1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hl=de; PHPSESSID=ak93pqashi5uubuoq8fjv60897');
     $this->assertEquals('1.638370270.1344367610.1374365610.1944450276.2', $this->request->getCookie('__utma'));
     $this->assertEquals('1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', $this->request->getCookie('__utmz'));
     $this->assertEquals('de', $this->request->getCookie('hl'));
     $this->assertEquals('ak93pqashi5uubuoq8fjv60897', $this->request->getCookie('PHPSESSID'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     $this->request->removeHeader('Cookie');
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
     // Remove a cookie value
     $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
     $this->request->removeCookie('foo');
     $this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
     $this->request->addCookie('foo', 'bar');
     $this->assertEquals('baz=boo; foo=bar', (string) $this->request->getHeader('Cookie'));
 }
开发者ID:jorjoh,项目名称:Varden,代码行数:32,代码来源:RequestTest.php

示例5: send

 /**
  * Send the request
  */
 public function send()
 {
     // make a request object
     $this->request = $this->client->createRequest($this->method, $this->host . $this->resource);
     // set headers
     foreach ($this->headers as $header => $value) {
         $this->request->setHeader($header, $value);
     }
     // set body
     if (!empty($this->body)) {
         $this->request->setBody($this->body);
     }
     try {
         // finally send the request
         $this->response = $this->client->send($this->request);
     } catch (BadResponseException $e) {
         $this->response = $this->request->getResponse();
     }
     $this->sent = true;
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:23,代码来源:GuzzleDriver.php

示例6: setRequestAuthentication

 public function setRequestAuthentication(\Guzzle\Http\Message\Request $request)
 {
     $oauthAccessToken = $this->configuration->get('oauthAccessToken');
     // Do we have an oAuth2 access token?
     if (!empty($oauthAccessToken)) {
         $request->setHeader('Authorization', 'Bearer ' . $oauthAccessToken);
     } else {
         // Otherwise, use basic authentication
         $request->setAuth($this->configuration->get('apiToken'), $this->configuration->get('apiSecret'));
     }
     return $request;
 }
开发者ID:TheJaniceTong,项目名称:PhpSdk,代码行数:12,代码来源:Request.php

示例7: iRequest

 /**
  * @When /^I request "(GET|PUT|POST|DELETE|PATCH) ([^"]*)"$/
  */
 public function iRequest($httpMethod, $resource)
 {
     // process any %battles.last.id% syntaxes
     $resource = $this->processReplacements($resource);
     $this->resource = $resource;
     // reset the response payload
     $this->responsePayload = null;
     $method = strtolower($httpMethod);
     try {
         switch ($httpMethod) {
             case 'PUT':
             case 'POST':
             case 'PATCH':
                 // process any %user.weaverryan.id% syntaxes
                 $payload = $this->processReplacements($this->requestPayload);
                 $this->lastRequest = $this->client->{$method}($resource, null, $payload);
                 break;
             default:
                 $this->lastRequest = $this->client->{$method}($resource);
         }
         if ($this->authUser) {
             $this->lastRequest->setAuth($this->authUser, $this->authPassword);
         }
         foreach ($this->headers as $key => $val) {
             $this->lastRequest->setHeader($key, $val);
         }
         $this->response = $this->lastRequest->send();
     } catch (BadResponseException $e) {
         $response = $e->getResponse();
         // Sometimes the request will fail, at which point we have
         // no response at all. Let Guzzle give an error here, it's
         // pretty self-explanatory.
         if ($response === null) {
             throw $e;
         }
         $this->response = $e->getResponse();
     }
 }
开发者ID:rllmwm,项目名称:forbiddencat,代码行数:41,代码来源:ApiFeatureContext.php

示例8: setHeader

 public function setHeader($name, $value)
 {
     $this->_request->setHeader($name, $value);
     return $this;
 }
开发者ID:sokil,项目名称:php-rest,代码行数:5,代码来源:Request.php

示例9: generateRequest

 protected function generateRequest($url, array $subProtocols, array $headers)
 {
     $headers = array_merge($this->defaultHeaders, $headers);
     $headers['Sec-WebSocket-Key'] = $this->generateKey();
     $request = new Request('GET', $url, $headers);
     $scheme = strtolower($request->getScheme());
     if (!in_array($scheme, ['ws', 'wss'])) {
         throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
     }
     $request->setScheme('HTTP');
     if (!$request->getPort()) {
         $request->setPort('wss' === $scheme ? 443 : 80);
     } else {
         $request->setHeader('Host', $request->getHeader('Host') . ":{$request->getPort()}");
     }
     if (!$request->getHeader('Origin')) {
         $request->setHeader('Origin', str_replace('ws', 'http', $scheme) . '://' . $request->getHost());
     }
     // do protocol headers
     if (count($subProtocols) > 0) {
         $protocols = implode(',', $subProtocols);
         if ($protocols != "") {
             $request->setHeader('Sec-WebSocket-Protocol', $protocols);
         }
     }
     return $request;
 }
开发者ID:brainverb,项目名称:Pawl,代码行数:27,代码来源:Factory.php

示例10: setHeaders

 /**
  * Function to set headers on the request
  *
  * @param  array  $requestHeaders  Any additional headers for the request
  * @return  void
  */
 public function setHeaders($requestHeaders = array())
 {
     foreach ($requestHeaders as $header => $value) {
         $this->request->setHeader($header, $value);
     }
 }
开发者ID:summer11123,项目名称:trucker,代码行数:12,代码来源:RestRequest.php

示例11: bindAccept

 /**
  * 
  * @param \Guzzle\Http\Message\Request $request
  * @return \ChartBlocks\Client
  */
 public function bindAccept(HttpRequest $request)
 {
     $request->setHeader('Accept', 'application/json');
     return $this;
 }
开发者ID:chartblocks,项目名称:php-rest-sdk,代码行数:10,代码来源:Client.php

示例12: send

 /**
  * @param \Guzzle\Http\Message\Request $request
  * @return \Guzzle\Http\Message\Response
  */
 public function send(\Guzzle\Http\Message\Request $request)
 {
     $token = $this->getToken();
     $request->setHeader('X-Auth-Token', $token['token'])->setHeader('Content-Type', 'application/json')->setHeader('X-Auth-UserId', $token['user_id']);
     return $request->send();
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:10,代码来源:Request.php


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