本文整理汇总了PHP中Httpful\Request::addHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::addHeaders方法的具体用法?PHP Request::addHeaders怎么用?PHP Request::addHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Httpful\Request
的用法示例。
在下文中一共展示了Request::addHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeRequest
/**
* function config to make request
*
* @param $params
* @param $function
* @param $type (only allow get post put delete head and options)
* @return bool
*/
public function makeRequest($function, $params = [], $type = 'post')
{
if (!in_array($type, ['get', 'post', 'put', 'delete', 'head', 'options'])) {
return false;
}
$url = $this->_baseApiUrl . $function;
$this->_client = Client::$type($url);
$header = ['Content-Type' => 'application/json'];
$baseParams = ['ApiKey' => $this->_key, 'ApiSecretKey' => $this->_secretKey, 'ClientID' => $this->_clientId, 'Password' => $this->_password];
$configParam = array_merge($baseParams, $params);
return $this->_client->addHeaders($header)->body(json_encode($configParam))->send();
}
示例2: setHeaders
/**
* Установка заголовков для корректной работы с Rutube
* @param string $token
* @return mixed
*/
public function setHeaders($token = null)
{
$headers = array('Accept' => 'application/json', 'User-Agent' => 'Rutube_PHPClient');
if ($token !== null) {
$headers['Authorization'] = 'Token ' . $token;
}
$this->request->addHeaders($headers);
return $this;
}