本文整理汇总了PHP中Buzz\Message\Request::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setHeaders方法的具体用法?PHP Request::setHeaders怎么用?PHP Request::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Buzz\Message\Request
的用法示例。
在下文中一共展示了Request::setHeaders方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareRequest
/**
* @param Request $request
* @return BuzzRequest
*/
protected function prepareRequest(Request $request)
{
$buzzRequest = new BuzzRequest($request->getMethod(), $request->getUrl()->getResource(), $request->getUrl()->getHost());
$buzzRequest->setProtocolVersion($request->getProtocolVersion());
$buzzRequest->setHeaders(HeaderConverter::convertAssociativeToRaw($this->prepareHeaders($request)));
$buzzRequest->setContent($request->getContent());
return $buzzRequest;
}
示例2: createRequest
/**
* Create request instance
*
* @param string $method Request method
* @param string $path Request path
* @param array $body Request body array
*/
protected function createRequest($method, $path, array $body)
{
$request = new Request($method, $path, $this->createHost());
$request->setHeaders(['Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json', 'X-Stream' => 'true']);
$request->addHeader('Authorization: Basic ' . base64_encode($this->options['username'] . ':' . $this->options['password']));
$request->setContent(json_encode($body));
return $request;
}
示例3: provideIdenticalGetRequestsInDifferentFormats
public function provideIdenticalGetRequestsInDifferentFormats()
{
$data = array();
$textRequest = $this->loadRequest('example.com');
$guzzleRequest = $this->getRequestFactory()->fromMessage($textRequest);
$buzzRequest = new BuzzRequest($guzzleRequest->getMethod(), $guzzleRequest->getPath());
$buzzRequest->setHeaders($guzzleRequest->getHeaderLines());
$zendRequest = ZendRequest::fromString($textRequest);
$requests = array($buzzRequest, $guzzleRequest, $textRequest, $zendRequest);
foreach ($requests as $request1) {
foreach ($requests as $request2) {
// Don't compare a request with itself
if ($request1 !== $request2) {
continue;
}
$data[] = array($request1, $request2);
}
}
return $data;
}
示例4: removeCsrfHeader
/**
* Removes the CSRF token header from a $request.
*
* @param Request $request
*/
private function removeCsrfHeader(Request $request)
{
foreach ($request->getHeaders() as $headerString) {
list($headerName) = explode(': ', $headerString);
if (strtolower($headerName) !== 'x-csrf-token') {
$headers[] = $headerString;
}
}
$request->setHeaders($headers);
}
示例5: httpRequest
/**
* Performs an HTTP request
*
* @param string $url The url to fetch
* @param string|array $content The content of the request
* @param array $headers The headers of the request
* @param string $method The HTTP method to use
*
* @return HttpResponse The response content
*/
protected function httpRequest($url, $content = null, $headers = array(), $method = null)
{
if (null === $method) {
$method = null === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST;
}
$request = new HttpRequest($method, $url);
$response = new HttpResponse();
$contentLength = 0;
if (is_string($content)) {
$contentLength = strlen($content);
} elseif (is_array($content)) {
$contentLength = strlen(implode('', $content));
}
$headers = array_merge(array('User-Agent: HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)', 'Content-Length: ' . $contentLength), $headers);
$request->setHeaders($headers);
$request->setContent($content);
$this->httpClient->send($request, $response);
return $response;
}
示例6: doHttpRequest
/**
* @param array $parameters
*
* @return array
*/
protected function doHttpRequest($parameters)
{
$request = new Request(RequestInterface::METHOD_POST, self::OAUTH2_ACCESS_TOKEN_URL);
$response = new Response();
$contentParameters = ['client_id' => $this->configManager->get('oro_google_integration.client_id'), 'client_secret' => $this->configManager->get('oro_google_integration.client_secret')];
$parameters = array_merge($contentParameters, $parameters);
$content = http_build_query($parameters, '', '&');
$headers = ['Content-length: ' . strlen($content), 'content-type: application/x-www-form-urlencoded', 'user-agent: oro-oauth'];
$request->setHeaders($headers);
$request->setContent($content);
$this->httpClient->send($request, $response);
return $this->getResponseContent($response);
}
示例7: httpRequest
/**
* Performs an HTTP request
*
* @param string $url The url to fetch
* @param string|array $content The content of the request
* @param array $headers The headers of the request
* @param string $method The HTTP method to use
*
* @return HttpResponse The response content
*/
protected function httpRequest($url, $content = null, $headers = array(), $method = null)
{
if (null === $method) {
$method = null === $content || '' === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST;
}
$request = new HttpRequest($method, $url);
$response = new HttpResponse();
$contentLength = 0;
if (is_string($content)) {
$contentLength = strlen($content);
} elseif (is_array($content)) {
$contentLength = strlen(implode('', $content));
}
$headers = array_merge(array('User-Agent: HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)', 'Content-Length: ' . $contentLength), $headers);
$request->setHeaders($headers);
$request->setContent($content);
try {
$this->httpClient->send($request, $response);
} catch (ClientException $e) {
throw new HttpTransportException('Error while sending HTTP request', $this->getName(), $e->getCode(), $e);
}
return $response;
}
示例8: request
/**
* Make HTTP Request.
*
* @return mixed[]
*/
public function request($method, $resource, $params = [], $timeout = 10)
{
$headers = ['User-Agent: ' . $this->getAccountData()['appName'], 'Content-Type: application/json'];
$storage = Storage::get();
$hash = $storage->createHash($method, $resource, $params);
$etag = $storage->get($hash);
if ($etag) {
$headers[] = 'If-None-Match: ' . $etag;
}
$message = new Request($method, $resource, self::BASE_URL . $this->getAccountData()['accountId'] . self::API_VERSION);
$message->setHeaders($headers);
if (!empty($params)) {
// When attaching files set content as is
if (array_key_exists('binary', $params)) {
$message->setContent($params['binary']);
} else {
$message->setContent(json_encode($params));
}
}
$response = new Response();
$bc = $this->createCurl();
$bc->setTimeout($timeout);
if (!empty($this->getAccountData()['login']) && !empty($this->getAccountData()['password'])) {
$bc->setOption(CURLOPT_USERPWD, $this->getAccountData()['login'] . ':' . $this->getAccountData()['password']);
} elseif (!empty($this->getAccountData()['token'])) {
$message->addHeader('Authorization: Bearer ' . $this->getAccountData()['token']);
}
$bc->send($message, $response);
$storage->put($hash, trim($response->getHeader('ETag'), '"'));
$data = new \stdClass();
switch ($response->getStatusCode()) {
case 201:
$data = json_decode($response->getContent());
$data->message = 'Created';
break;
case 204:
$data->message = 'Resource succesfully deleted';
break;
case 304:
$data->message = '304 Not Modified';
break;
case 400:
$data->message = '400 Bad Request';
break;
case 403:
$data->message = '403 Forbidden';
break;
case 404:
$data->message = '404 Not Found';
break;
case 415:
$data->message = '415 Unsupported Media Type';
break;
case 429:
$data->message = '429 Too Many Requests. ' . $response->getHeader('Retry-After');
break;
case 500:
$data->message = '500 Hmm, that isn�t right';
break;
case 502:
$data->message = '502 Bad Gateway';
break;
case 503:
$data->message = '503 Service Unavailable';
break;
case 504:
$data->message = '504 Gateway Timeout';
break;
default:
$data = json_decode($response->getContent());
break;
}
return $data;
}
示例9: httpRequest
/**
*
* Performs an HTTP request
*
* @param string $url The url to fetch
* @param string $content The content of the request
* @param array $headers The headers of the request
* @param string $method The HTTP method to use
*
* @return string The response content
*/
protected function httpRequest($url, $content = null, $headers = array(), $method = null)
{
if (null === $method) {
$method = null === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST;
}
$request = new HttpRequest($method, $url);
$response = new HttpResponse();
$request->setHeaders($headers);
$request->setContent($content);
$this->httpClient->send($request, $response);
return $response;
}
示例10: request
/**
* Generic request manager to betaseries API
*
* @param string $queryString Query string of the request
* @param string $method Http method of the request
* @param array $params Array containing param list
*
* @return array Response of the request ("json_decoded")
*
* @throws PatbzhBetaseriesException In case betaseries api sends an error response
*/
protected function request($queryString, $method, $params = null)
{
$queryStringComplement = '';
if ($params !== null) {
$queryStringComplement = '?' . http_build_query($params);
}
$request = new Request($method, $queryString . $queryStringComplement, self::BETA_SERIES_BASE_URL);
$request->setHeaders(array('Accept' => 'text/json', 'X-BetaSeries-Version' => $this->getApiVersion(), 'X-BetaSeries-Key' => $this->getApiKey(), 'X-BetaSeries-Token' => $this->getOauthUserToken(), 'User-agent' => $this->getUserAgent()));
$response = new Response();
$this->httpClient->send($request, $response);
$parsedResponse = json_decode($response->getContent(), true);
if ($response->getStatusCode() == 400) {
throw new PatbzhBetaseriesException($parsedResponse['errors'][0]['text'] . ' (' . $parsedResponse['errors'][0]['code'] . ')', $parsedResponse['errors'][0]['code']);
}
return $parsedResponse;
}
示例11: httpRequest
/**
* Performs an HTTP request
*
* @param string $url The url to fetch
* @param string $content The content of the request
* @param array $headers The headers of the request
* @param string $method The HTTP method to use
*
* @return HttpResponse The response content
*/
protected function httpRequest($url, $content = null, $headers = array(), $method = null)
{
if (null === $method) {
$method = null === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST;
}
$request = new HttpRequest($method, $url);
$response = new HttpResponse();
$headers = array_merge(array('User-Agent: HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)'), $headers);
$request->setHeaders($headers);
$request->setContent($content);
$this->httpClient->send($request, $response);
return $response;
}
示例12: httpRequest
/**
* Code below is borrowed from HWIOAuthBundle
*
* @see HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\GenericOAuth1ResourceOwner
*/
private function httpRequest($url, $content = null, $parameters = array(), $headers = array(), $method)
{
$authorization = 'Authorization: OAuth';
foreach ($parameters as $key => $value) {
$value = rawurlencode($value);
$authorization .= ", {$key}=\"{$value}\"";
}
$headers[] = $authorization;
$request = new Request($method, $url);
$response = new Response();
$request->setHeaders($headers);
$request->setContent($content);
$this->httpClient->send($request, $response);
return $response;
}