本文整理汇总了PHP中Httpful\Request::addHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::addHeader方法的具体用法?PHP Request::addHeader怎么用?PHP Request::addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Httpful\Request
的用法示例。
在下文中一共展示了Request::addHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendRequest
/**
* 执行http发送请求
*
* @throws \Httpful\Exception\ConnectionErrorException
*/
protected function sendRequest()
{
!$this->httpful and $this->httpful = Request::init($this->method);
$payload = '';
if (in_array($this->httpful->method, ['POST', 'PUT'])) {
$payload = $this->makePayload();
}
$uri = $this->account->getSchemeHost() . $this->requestResource;
$this->urlParams and $uri .= '?' . http_build_query($this->urlParams) and $this->requestResource .= '?' . http_build_query($this->urlParams);
$this->httpful->uri($uri);
$this->httpful->addHeader('Content-Length', strlen($payload));
$this->httpful->addHeader('Content-MD5', base64_encode(md5($payload)));
$this->httpful->addHeader('Content-Type', 'text/xml;utf-8');
$this->httpful->addHeader('Date', date('D, d M Y H:i:s', time()) . ' GMT');
$this->httpful->addHeader('Host', $this->account->getHost());
$this->makeSpecificHeaders();
$this->httpful->body($payload);
$this->httpful->addHeader('Authorization', $this->makeSignature());
try {
return $this->httpful->send();
} catch (\Exception $e) {
return new Response(sprintf(<<<EOF
<?xml version="1.0"?>
<Error xmlns="http://mqs.aliyuncs.com/doc/v1">
<Code>%s</Code>
<Message>%s</Message>
<RequestId>0</RequestId>
<HostId>%s</HostId>
</Error>
EOF
, $e->getCode(), $e->getMessage() . '; FILE: ' . $e->getFile() . '; LINE: ' . $e->getLine(), $this->account->getSchemeHost()), "HTTP/1.1 400 OK\r\nServer: MOCK-SERVER\r\nContent-Type: text/xml;charset=utf-8\r\nx-mqs-request-id: 0", $this->httpful);
}
}
示例2: send
/**
* Выполнение запроса
* @return \Httpful\associative|string
*
* @throws \Httpful\Exception\ConnectionErrorException
*/
public function send()
{
if ($this->userAgent !== null) {
$this->request->addHeader('User-Agent', $this->userAgent);
}
if ($this->x_real_ip !== null) {
$this->request->addHeader('X-Real-IP', $this->x_real_ip);
}
return $this->request->timeout(self::TIMEOUT)->send();
}
示例3: signRequest
public function signRequest(\Httpful\Request $request)
{
$url = $request->uri;
$consumer_key = $this->consumer_key;
$consumer_secret = $this->consumer_secret;
$oauth_access_token = $this->access_token;
$oauth_access_token_secret = $this->access_token_secret;
$oauth = array('oauth_consumer_key' => $consumer_key, 'oauth_nonce' => hash('sha512', $this->makeRandomString()), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
list($uri, $getfield) = explode('?', $url);
if (!is_null($getfield)) {
$getfields = str_replace('?', '', explode('&', $getfield));
foreach ($getfields as $g) {
$split = explode('=', $g);
/** In case a null is passed through **/
if (isset($split[1])) {
$oauth[$split[0]] = urldecode($split[1]);
}
}
}
$postfields = $request->payload;
if (!is_null($postfields)) {
$postfields = explode('&', $postfields);
foreach ($postfields as $g) {
$split = explode('=', $g);
/** In case a null is passed through **/
if (isset($split[1])) {
$oauth[$split[0]] = urldecode($split[1]);
}
}
}
$base_info = $this->buildBaseString($url, strtoupper($request->method), $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$authorisationHeader = $this->buildAuthorizationHeader($oauth);
$request->addHeader('Authorization', $authorisationHeader);
return $request;
}
示例4: addAuthenticationHeadersToRequest
protected function addAuthenticationHeadersToRequest(\Httpful\Request &$request, $resourcePath)
{
$sm = new SecurityManager();
$timestamp = new \DateTime();
$timestamp = $timestamp->format('YmdHis');
$xapiPublicKey = $this->_xapiSdkConf->getXapiPublicKey();
$xapiPrivateKey = $this->_xapiSdkConf->getXapiPrivateKey();
$hashSignature = $sm->calculateSignatureForRequest($resourcePath, $xapiPublicKey, $xapiPrivateKey, $timestamp);
$request->addHeader(self::HEADER_NAME__APIKEY, $xapiPublicKey);
$request->addHeader(self::HEADER_NAME__TIMESTAMP, $timestamp);
$request->addHeader(self::HEADER_NAME__SIGNATURE, $hashSignature);
}