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


PHP RequestInterface::setHeader方法代码示例

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


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

示例1: 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);
     }
     $request->removeHeader('x-amz-date');
     $request->setHeader('Date', gmdate(\DateTime::RFC2822));
     $stringToSign = $this->createCanonicalizedString($request);
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     $request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
     //         COMMONLOG(DEBUG, "send header:%s",$request->getRawHeaders());
     //         if(self::$isFile)
     //         {
     //         	if(self::$filePath)
     //         		COMMONLOG(DEBUG, "souce file:%s",self::$filePath);
     //         }
     //         else
     //        {
     //        		if(get_class($request) === 'Guzzle\Http\Message\EntityEnclosingRequest' && get_class($request->getBody()) === 'Guzzle\Http\EntityBody' &&  $request->getBody()->getContentLength() != 0)
     //        		{
     //        			COMMONLOG(DEBUG, "send msg:%s",$request->getBody());
     //        		}
     //         }
 }
开发者ID:eSDK,项目名称:esdk_obs_native_php,代码行数:27,代码来源:S3Signature.php

示例2: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Refresh the cached timestamp
     $this->getTimestamp(true);
     // Add default headers
     $request->setHeader('x-amz-date', $this->getDateTime(DateFormat::RFC1123));
     // Add the security token if one is present
     if ($credentials->getSecurityToken()) {
         $request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
     }
     // Grab the path and ensure that it is absolute
     $path = '/' . ltrim($request->getUrl(true)->normalizePath()->getPath(), '/');
     // Begin building the string to sign
     $sign = $request->getMethod() . "\n" . "{$path}\n" . $this->getCanonicalizedQueryString($request) . "\n";
     // Get all of the headers that must be signed (host and x-amz-*)
     $headers = $this->getHeadersToSign($request);
     foreach ($headers as $key => $value) {
         $sign .= $key . ':' . $value . "\n";
     }
     $sign .= "\n";
     // Add the body of the request if a body is present
     if ($request instanceof EntityEnclosingRequestInterface) {
         $sign .= (string) $request->getBody();
     }
     // Add the string to sign to the request for debugging purposes
     $request->getParams()->set('aws.string_to_sign', $sign);
     $signature = base64_encode(hash_hmac('sha256', hash('sha256', $sign, true), $credentials->getSecretKey(), true));
     // Add the authorization header to the request
     $request->setHeader('x-amzn-authorization', sprintf('AWS3 AWSAccessKeyId=%s,Algorithm=HmacSHA256,SignedHeaders=%s,Signature=%s', $credentials->getAccessKeyId(), implode(';', array_keys($headers)), $signature));
 }
开发者ID:congtrieu112,项目名称:anime,代码行数:33,代码来源:SignatureV3.php

示例3: signRequest

 /**
  * @param RequestInterface|EntityEnclosingRequestInterface $request
  * @param Credentials $credentials
  */
 public function signRequest($request, $credentials)
 {
     $request->setHeader('X-HMB-Signature-Method', self::DEFAULT_METHOD);
     $request->setHeader('X-HMB-Signature-Version', self::DEFAULT_SIGN_VERSION);
     $request->setHeader('X-HMB-TimeStamp', time());
     $contentMd5 = $request instanceof EntityEnclosingRequestInterface ? md5($request->getBody()) : '';
     if ($contentMd5) {
         $request->setHeader('Content-MD5', $contentMd5);
     }
     $sign = array();
     $sign[] = strtoupper($request->getMethod());
     $sign[] = $request->getHost();
     if ($request->getHeader('Content-MD5')) {
         $sign[] = $request->getHeader('Content-MD5');
     }
     if ($request->getHeader('Content-Type')) {
         $sign[] = $request->getHeader('Content-Type');
     }
     $sign[] = $request->getHeader('X-HMB-Signature-Method');
     $sign[] = $request->getHeader('X-HMB-Signature-Version');
     $sign[] = $request->getHeader('X-HMB-TimeStamp');
     if ($request->getHeader('X-HMB-User-Session-Token')) {
         $sign[] = $request->getHeader('X-HMB-User-Session-Token');
     }
     $sign[] = $request->getQuery(true) ? $request->getPath() . '?' . $request->getQuery(true) : $request->getPath();
     $signature = base64_encode(hash_hmac(strtolower($request->getHeader('X-HMB-Signature-Method')), implode("\n", $sign), $credentials->getSecret()));
     $request->setHeader('Authorization', sprintf('%s %s:%s', self::AUTHORIZATION_SCHME, $credentials->getKey(), $signature));
 }
开发者ID:sonicmoov,项目名称:hmb-sdk-php,代码行数:32,代码来源:Signature.php

示例4: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()) {
         $request->setHeader('X-Amz-Content-Sha256', EntityBody::getHash($request->getBody(), 'sha256'));
     } else {
         $request->setHeader('X-Amz-Content-Sha256', hash('sha256', ''));
     }
     parent::signRequest($request, $credentials);
 }
开发者ID:mahassan,项目名称:shellneverknow,代码行数:9,代码来源:S3SignatureV4.php

示例5: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Add a date header if one is not set
     if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
         $request->setHeader('Date', gmdate(DateFormat::RFC2822));
     }
     $stringToSign = (string) $request->getHeader('Date') ?: (string) $request->getHeader('x-amz-date');
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     $request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
 }
开发者ID:risyasin,项目名称:webpagetest,代码行数:13,代码来源:CloudFrontSignature.php

示例6: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // 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
     if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
         $request->setHeader('Date', gmdate(DateFormat::RFC2822));
     }
     $stringToSign = $this->createCanonicalizedString($request);
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     $request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
 }
开发者ID:noahkim,项目名称:kowop,代码行数:17,代码来源:S3Signature.php

示例7: after

public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;


 if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {

 $operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}

if ($xml) {

 if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:25,代码来源:XmlVisitor.php

示例8: signRequest

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

示例9: setHeaders

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 private function setHeaders(RequestInterface $request)
 {
     foreach ($this->headers as $name => $value) {
         $request->setHeader($name, $value);
     }
     return $request;
 }
开发者ID:erliz,项目名称:jira-api-client-guzzle-provider,代码行数:12,代码来源:Client.php

示例10: 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:nstanard,项目名称:webpagetest,代码行数:10,代码来源:S3SignatureV4.php

示例11: after

 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
         $request->setBody(json_encode($this->data[$command]));
         unset($this->data[$command]);
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:10,代码来源:JsonVisitor.php

示例12: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Add a date header if one is not set
     if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
         $request->setHeader('Date', $this->getDateTime(DateFormat::RFC1123));
     }
     // Add the security token if one is present
     if ($credentials->getSecurityToken()) {
         $request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
     }
     // Determine the string to sign
     $stringToSign = $request->getHeader('Date', true) ?: $request->getHeader('x-amz-date', true);
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     // Calculate the signature
     $signature = base64_encode(hash_hmac('sha256', $stringToSign, $credentials->getSecretKey(), true));
     // Add the authorization header to the request
     $headerFormat = 'AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s';
     $request->setHeader('X-Amzn-Authorization', sprintf($headerFormat, $credentials->getAccessKeyId(), $signature));
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:22,代码来源:SignatureV3Https.php

示例13: addPrefixedHeaders

 /**
  * Add a prefixed array of headers to the request
  *
  * @param RequestInterface $request Request to update
  * @param Parameter        $param   Parameter object
  * @param array            $value   Header array to add
  *
  * @throws InvalidArgumentException
  */
 protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
 {
     if (!is_array($value)) {
         throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
     }
     $prefix = $param->getSentAs();
     foreach ($value as $headerName => $headerValue) {
         $request->setHeader($prefix . $headerName, $headerValue);
     }
 }
开发者ID:xkeygmbh,项目名称:ifresco-php,代码行数:19,代码来源:HeaderVisitor.php

示例14: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $xml = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody($xml->asXML());
         if ($this->contentType) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
开发者ID:xkeygmbh,项目名称:ifresco-php,代码行数:14,代码来源:XmlVisitor.php

示例15: after

 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody(json_encode($json))->removeHeader('Expect');
         if ($this->jsonContentType) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
     }
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:14,代码来源:JsonBodyVisitor.php


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