本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::addHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::addHeader方法的具体用法?PHP RequestInterface::addHeader怎么用?PHP RequestInterface::addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::addHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRequest
/**
* @param RequestInterface $request
* @param bool $acceptJsonResponse
*/
protected function buildRequest(RequestInterface $request, $acceptJsonResponse = true)
{
if ($acceptJsonResponse) {
$request->addHeader('Accept', 'application/json');
}
$request->addHeader('Accept-Charset', 'UTF-8');
}
示例2: addAuthTokenHeader
/**
* @param RequestInterface $request
*/
private function addAuthTokenHeader(RequestInterface $request)
{
$request->addHeader('Authorization', 'Bearer ' . $this->getAuthToken());
}
示例3: send
/**
* Set HTTP request to activeCollab API
* @param RequestInterface $request
* @param bool $authenticate
* @return object
* @throws Exception\ApiException
* @throws Exception\AuthenticationFailedException
*/
public function send(RequestInterface $request, $authenticate = true)
{
$request->addHeader('Accept', 'application/json');
if ($authenticate) {
$request->setQuery($request->getQuery()->set('auth_api_token', $this->api_token));
}
/** @var ResponseInterface $response */
$response = $this->client->send($request);
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
switch ($response->getStatusCode()) {
case 403:
throw new AuthenticationFailedException($response);
default:
throw new ApiException($response);
}
}
return $this->parseResponse($request, $response);
}
示例4: withJsonContentType
public function withJsonContentType()
{
$this->expectedRequest->addHeader('Content-Type', 'application/json');
return $this;
}