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


PHP RequestInterface::setHeader方法代码示例

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


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

示例1: applyRequestHeaders

 /**
  * Applies request headers to a request based on the POST state
  *
  * @param RequestInterface $request Request to update
  */
 public function applyRequestHeaders(RequestInterface $request)
 {
     if ($this->files || $this->forceMultipart) {
         $request->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->getBody()->getBoundary());
     } elseif ($this->fields) {
         $request->setHeader('Content-Type', 'application/x-www-form-urlencoded');
     }
     if ($size = $this->getSize()) {
         $request->setHeader('Content-Length', $size);
     }
 }
开发者ID:GTAWWEKID,项目名称:tsiserver.us,代码行数:16,代码来源:PostBody.php

示例2: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Ensure that the signable query string parameters are sorted
     sort($this->signableQueryString);
     // Add the security token header if one is being used by the credentials
     if ($token = $credentials->getSecurityToken()) {
         $request->setHeader('X-Amz-Security-Token', $token);
     }
     // Add a date header if one is not set
     $request->removeHeader('X-Amz-Date');
     $request->setHeader('Date', gmdate(\DateTime::RFC2822));
     $stringToSign = $this->createCanonicalizedString($request);
     $request->getConfig()['aws.signature'] = $stringToSign;
     $request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:15,代码来源:S3Signature.php

示例3: signRequest

 /**
  * Always add a x-amz-content-sha-256 for data integrity.
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     if (!$request->hasHeader('x-amz-content-sha256')) {
         $request->setHeader('X-Amz-Content-Sha256', $this->getPayload($request));
     }
     parent::signRequest($request, $credentials);
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:10,代码来源:S3SignatureV4.php

示例4: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     foreach ($this->buffered as $param) {
         $this->visitWithValue($command[$param->getName()], $param, $command);
     }
     $this->buffered = array();
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $additional->setName($key);
                 $this->visitWithValue($value, $additional, $command);
             }
         }
         $additional->setName(null);
     }
     // If data was found that needs to be serialized, then do so
     $xml = null;
     if ($this->writer) {
         $xml = $this->finishDocument($this->writer);
     } elseif ($operation->getData('xmlAllowEmpty')) {
         // Check if XML should always be sent for the command
         $writer = $this->createRootElement($operation);
         $xml = $this->finishDocument($writer);
     }
     if ($xml) {
         $request->setBody(Stream::factory($xml));
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
     $this->writer = null;
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:34,代码来源:XmlLocation.php

示例5: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     $ldt = gmdate(self::ISO8601_BASIC);
     $sdt = substr($ldt, 0, 8);
     $request->removeHeader('Authorization');
     $request->removeHeader('x-amz-date');
     $request->setHeader('Date', $ldt);
     if ($token = $credentials->getSecurityToken()) {
         $request->setHeader('x-amz-security-token', $token);
     }
     $cs = $this->createScope($sdt, $this->region, $this->service);
     $payload = $this->getPayload($request);
     $context = $this->createContext($request, $payload);
     $context['string_to_sign'] = $this->createStringToSign($ldt, $cs, $context['creq']);
     $signingKey = $this->getSigningKey($sdt, $this->region, $this->service, $credentials->getSecretKey());
     $signature = hash_hmac('sha256', $context['string_to_sign'], $signingKey);
     $request->setHeader('Authorization', "AWS4-HMAC-SHA256 " . "Credential={$credentials->getAccessKeyId()}/{$cs}, " . "SignedHeaders={$context['headers']}, Signature={$signature}");
     $request->getConfig()['aws.signature'] = $context;
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:19,代码来源:SignatureV4.php

示例6: setGuzzleHeaders

 /**
  * Set Headers for a Request specified by $headers.
  *
  * @param RequestInterface $request a Guzzle Request
  * @param array            $headers headers to set (should be an assoc array).
  */
 private function setGuzzleHeaders(RequestInterface $request, array $headers)
 {
     //iterate over the headers array and set each item
     foreach ($headers as $key => $value) {
         //Sets Header
         $request->setHeader($key, $value);
     }
     //return the request
     return $request;
 }
开发者ID:backupManager,项目名称:Twitter-API-PHP,代码行数:16,代码来源:Connection.php

示例7: after

 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $request->setHeader($key, $additional->filter($value));
             }
         }
     }
 }
开发者ID:ryanwinchester-forks,项目名称:guzzle-services,代码行数:11,代码来源:HeaderLocation.php

示例8: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $data = $this->jsonData;
     $this->jsonData = null;
     // Add additional parameters to the JSON document
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $data[$key] = $this->prepareValue($value, $additional);
             }
         }
     }
     // Don't overwrite the Content-Type if one is set
     if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', $this->jsonContentType);
     }
     $request->setBody(Stream::factory(json_encode($data)));
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:19,代码来源:JsonLocation.php

示例9: add_decode_content

 private function add_decode_content(RequestInterface $request, $value)
 {
     if ($value === false) {
         return;
     }
     if ($value !== true) {
         $request->setHeader('Accept-Encoding', $value);
     }
     $request->getConfig()['decode_content'] = true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:10,代码来源:MessageFactory.php

示例10: sign

 public function sign(RequestInterface $request, $accessToken)
 {
     $request->setHeader('Authorization', 'Bearer ' . $accessToken);
 }
开发者ID:Quantomic,项目名称:guzzle5-oauth2-subscriber,代码行数:4,代码来源:BasicAuth.php

示例11: payload

 /**
  * @param RequestInterface $request
  * @param string           $name
  * @param mixed            $args
  *
  * @return \GuzzleHttp\Stream\StreamInterface|void
  */
 protected function payload(RequestInterface $request, $name, $args)
 {
     $request->setHeader('Content-Type', 'application/xml');
     $request->setBody(Stream::factory($this->serializer->serialize($args)));
 }
开发者ID:danielcosta,项目名称:sellercenter-sdk,代码行数:12,代码来源:RestXmlSerializer.php

示例12: applyOptions

 protected function applyOptions(RequestInterface $request, array $options = [])
 {
     $config = $request->getConfig();
     $emitter = $request->getEmitter();
     foreach ($options as $key => $value) {
         if (isset(self::$configMap[$key])) {
             $config[$key] = $value;
             continue;
         }
         switch ($key) {
             case 'allow_redirects':
                 if ($value === false) {
                     continue;
                 }
                 if ($value === true) {
                     $value = self::$defaultRedirect;
                 } elseif (!isset($value['max'])) {
                     throw new Iae('allow_redirects must be true, false, or an ' . 'array that contains the \'max\' key');
                 } else {
                     // Merge the default settings with the provided settings
                     $value += self::$defaultRedirect;
                 }
                 $config['redirect'] = $value;
                 $emitter->attach($this->redirectPlugin);
                 break;
             case 'decode_content':
                 if ($value === false) {
                     continue;
                 }
                 $config['decode_content'] = true;
                 if ($value !== true) {
                     $request->setHeader('Accept-Encoding', $value);
                 }
                 break;
             case 'headers':
                 if (!is_array($value)) {
                     throw new Iae('header value must be an array');
                 }
                 // Do not overwrite existing headers
                 foreach ($value as $k => $v) {
                     if (!$request->hasHeader($k)) {
                         $request->setHeader($k, $v);
                     }
                 }
                 break;
             case 'exceptions':
                 if ($value === true) {
                     $emitter->attach($this->errorPlugin);
                 }
                 break;
             case 'body':
                 if (is_array($value)) {
                     $this->addPostData($request, $value);
                 } elseif ($value !== null) {
                     $request->setBody(Stream::factory($value));
                 }
                 break;
             case 'auth':
                 if (!$value) {
                     continue;
                 }
                 if (is_array($value)) {
                     $type = isset($value[2]) ? strtolower($value[2]) : 'basic';
                 } else {
                     $type = strtolower($value);
                 }
                 $config['auth'] = $value;
                 if ($type == 'basic') {
                     $request->setHeader('Authorization', 'Basic ' . base64_encode("{$value['0']}:{$value['1']}"));
                 } elseif ($type == 'digest') {
                     // @todo: Do not rely on curl
                     $config->setPath('curl/' . CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
                     $config->setPath('curl/' . CURLOPT_USERPWD, "{$value['0']}:{$value['1']}");
                 }
                 break;
             case 'query':
                 if ($value instanceof Query) {
                     $original = $request->getQuery();
                     // Do not overwrite existing query string variables by
                     // overwriting the object with the query string data passed
                     // in the URL
                     $value->overwriteWith($original->toArray());
                     $request->setQuery($value);
                 } elseif (is_array($value)) {
                     // Do not overwrite existing query string variables
                     $query = $request->getQuery();
                     foreach ($value as $k => $v) {
                         if (!isset($query[$k])) {
                             $query[$k] = $v;
                         }
                     }
                 } else {
                     throw new Iae('query must be an array or Query object');
                 }
                 break;
             case 'cookies':
                 if ($value === true) {
                     static $cookie = null;
                     if (!$cookie) {
                         $cookie = new Cookie();
//.........这里部分代码省略.........
开发者ID:DeveloperOwl,项目名称:flipside.io,代码行数:101,代码来源:MessageFactory.php

示例13: after

 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $request->setHeader('Content-Type', 'application/x-www-form-urlencoded');
 }
开发者ID:conversely-io,项目名称:conversely-php,代码行数:4,代码来源:PutLocation.php

示例14: setupRequest

 /**
  * @param RequestInterface $request
  * @return RequestInterface
  */
 public function setupRequest(RequestInterface $request)
 {
     $identitiy = $this->getCurrentIdentity();
     if ($identitiy->getCookieJar() != null) {
         //todo
         // this seems pretty hacky... is there a better way to replace the cookie container of a request?
         // > Currently not @see https://github.com/guzzle/guzzle/issues/1028#issuecomment-96253542 - maybe with Guzzle 6
         // remove current cookie subscribers
         $emitter = $request->getEmitter();
         foreach ($emitter->listeners("complete") as $listener) {
             if (is_array($listener) && $listener[0] instanceof Cookie) {
                 $emitter->detach($listener[0]);
             }
         }
         // set new Cookie subscriber
         $cookie = new Cookie($identitiy->getCookieJar());
         $emitter->attach($cookie);
     }
     if ($identitiy->getUserAgent() != null) {
         $request->setHeader("user-agent", $identitiy->getUserAgent());
     }
     $headers = $identitiy->getDefaultRequestHeaders();
     if ($headers != null) {
         foreach ($headers as $key => $val) {
             $request->setHeader($key, $val);
         }
     }
     if ($identitiy->getReferer() != null && trim($identitiy->getReferer()) != "") {
         $request->setHeader("referer", $identitiy->getReferer());
     }
     $request = parent::setupRequest($request);
     return $request;
 }
开发者ID:paslandau,项目名称:guzzle-rotating-proxy-subscriber,代码行数:37,代码来源:RotatingIdentityProxy.php

示例15: applyHeaderMap

 /**
  * Note: This is currently only present in the Amazon S3 model.
  */
 private function applyHeaderMap(RequestInterface $request, $name, Shape $member, array $value)
 {
     $prefix = $member['locationName'];
     foreach ($value as $k => $v) {
         $request->setHeader($prefix . $k, $v);
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:10,代码来源:RestSerializer.php


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