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


PHP Request::addHeader方法代码示例

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


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

示例1: createHttpRequest

 /**
  * @return HttpRequest
  */
 public function createHttpRequest($method, $uri, $contentType = '', $acceptType = '')
 {
     $request = new HttpRequest($method, $uri, $this->httpHost);
     $request->addHeader('Authorization: Basic ' . base64_encode($this->httpAuth));
     $request->addHeader('Content-Type: ' . $this->generateMediaTypeString($contentType));
     $request->addHeader('Accept: ' . $this->generateMediaTypeString($acceptType));
     return $request;
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:11,代码来源:TestCase.php

示例2: isSpam

 /**
  * Tells if the data looks like spam
  *
  * @param array $data
  * @return boolean
  */
 public function isSpam(array $data)
 {
     $data['blog'] = $this->blogUrl;
     $request = new Message\Request('POST', '/1.1/comment-check', $this->getHost());
     $request->setContent(http_build_query($data));
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader(sprintf('Content-Length: %d', strlen($request->getContent())));
     $response = new Message\Response();
     $client = new Client\Curl();
     $client->send($request, $response);
     return 'true' == $response->getContent();
 }
开发者ID:sblmasta,项目名称:OrnicarAkismetBundle,代码行数:18,代码来源:AkismetBuzzAdapter.php

示例3: testConvertsARequestToAContextArray

 public function testConvertsARequestToAContextArray()
 {
     $request = new Message\Request('POST', '/resource/123', 'http://example.com');
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader('Content-Length: 15');
     $request->setContent('foo=bar&bar=baz');
     $client = new StreamClient();
     $client->setMaxRedirects(5);
     $client->setIgnoreErrors(false);
     $client->setTimeout(10);
     $expected = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 15", 'content' => 'foo=bar&bar=baz', 'protocol_version' => 1.0, 'ignore_errors' => false, 'max_redirects' => 5, 'timeout' => 10));
     $this->assertEquals($expected, $client->getStreamContextArray($request));
 }
开发者ID:kingsj,项目名称:core,代码行数:13,代码来源:AbstractStreamTest.php

示例4: request

 /**
  * Helper to send requests to Metrics API.
  *
  * @param string $path Path after metrics api version.
  * @param string $method HTTP Mthod, 'GET' or 'POST'.
  * @param array<string,array> $data Metrics data.
  *
  * @return stdClass
  */
 protected function request($path, $method, array $data = array())
 {
     $request = new Request();
     $response = new Response();
     $transport = $this->getTransport();
     $request->setMethod($method);
     $request->setResource($this->buildPath($path));
     $request->setHost(self::URI);
     $request->addHeader('Authorization: Basic ' . base64_encode($this->getAuthCredentials()));
     $request->addHeader('User-Agent: ' . $this->getUserAgent());
     if (count($data)) {
         $request->addHeader('Content-Type: application/json');
         $request->setContent(json_encode($data));
     }
     $transport->send($request, $response);
     return json_decode($response->getContent());
 }
开发者ID:nesQuick,项目名称:PHP-Metrics-Client,代码行数:26,代码来源:Client.php

示例5: 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;
 }
开发者ID:endyjasmi,项目名称:neo4j,代码行数:15,代码来源:CurlDriver.php

示例6: __construct

 public function __construct(Response $response, Request $request, Curl $client)
 {
     $this->response = $response;
     $request->setProtocolVersion(1.1);
     $request->addHeader('Content-Type: application/json');
     $this->request = $request;
     $client->setTimeout(5);
     $client->setIgnoreErrors(true);
     $this->client = $client;
 }
开发者ID:expressly,项目名称:php-common,代码行数:10,代码来源:ExternalRoute.php

示例7: testConvertsARequestToAContextArray

 public function testConvertsARequestToAContextArray()
 {
     $request = new Request('POST', '/resource/123', 'http://example.com');
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader('Content-Length: 15');
     $request->setContent('foo=bar&bar=baz');
     $client = new StreamClient();
     $client->setMaxRedirects(5);
     $client->setIgnoreErrors(false);
     $client->setTimeout(10);
     $expected = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 15", 'content' => 'foo=bar&bar=baz', 'protocol_version' => 1.1, 'ignore_errors' => false, 'follow_location' => true, 'max_redirects' => 6, 'timeout' => 10), 'ssl' => array('verify_peer' => true, 'verify_host' => 2));
     $this->assertEquals($expected, $client->getStreamContextArray($request));
     $client->setVerifyPeer(true);
     $expected['ssl']['verify_peer'] = true;
     $this->assertEquals($expected, $client->getStreamContextArray($request));
     $client->setMaxRedirects(0);
     $expected['http']['follow_location'] = false;
     $expected['http']['max_redirects'] = 1;
     $this->assertEquals($expected, $client->getStreamContextArray($request));
 }
开发者ID:ChazalFlorian,项目名称:enjoyPangolin,代码行数:20,代码来源:AbstractStreamTest.php

示例8: doHttpRequest

 /**
  * @param $method
  * @param $relativeUrl
  * @param array|\stdClass $content
  * @return mixed
  */
 protected function doHttpRequest($method, $relativeUrl, $content = null)
 {
     $relativeUrl = ltrim($relativeUrl, '/');
     $response = new Response();
     $request = new Request($method);
     $request->fromUrl($this->baseUrl . '/' . $relativeUrl);
     $request->addHeader("Content-Type: application/json");
     $request->addHeader('Accept: application/json');
     if ($content) {
         $request->setContent(json_encode(array_filter((array) $content)));
     }
     $timezone = new \DateTimeZone("UTC");
     $datetime = new \DateTime(null, $timezone);
     $timestamp = str_replace('-', '', $datetime->format('c'));
     $nonce = uniqid();
     $authToken = $this->makeAuthHeader($request, $timestamp, $nonce);
     $request->addHeader("Authorization: " . $authToken);
     // $listener = new BasicAuthListener($this->username, $this->password);
     // $listener->preSend($request);
     $this->httpClient->send($request, $response);
     return $this->getResult($response);
 }
开发者ID:bluestatedigital,项目名称:akamai-api-client,代码行数:28,代码来源:Client.php

示例9: performRequest

 private function performRequest($endpoint, array $params = array())
 {
     $uri = static::BASE_URI . '/' . ltrim($endpoint, '/') . '?' . http_build_query($params);
     $request = new Request(Request::METHOD_GET, $uri);
     $request->addHeader(sprintf('Authorization: Bearer %s', $this->accessToken));
     $response = new Response();
     $this->client->send($request, $response);
     $content = $response->getContent();
     if ($response->getStatusCode() !== 200) {
         throw new InvalidArgumentException('An error occurred while calling the spotify API (' . $uri . '): ' . $content);
     }
     return json_decode($content, true);
 }
开发者ID:hansott,项目名称:spotify-backupper,代码行数:13,代码来源:ClientBuzz.php

示例10: testConsecutiveRequests

 /**
  * @dataProvider provideClient
  */
 public function testConsecutiveRequests($client)
 {
     // request 1
     $request = new Request(Request::METHOD_PUT);
     $request->fromUrl($_SERVER['TEST_SERVER']);
     $request->addHeader('Content-Type: application/json');
     $request->setContent(json_encode(array('foo' => 'bar')));
     $response = new Response();
     $client->send($request, $response);
     $data = json_decode($response->getContent(), true);
     $this->assertEquals('PUT', $data['SERVER']['REQUEST_METHOD']);
     $this->assertEquals('application/json', $data['SERVER']['CONTENT_TYPE']);
     $this->assertEquals('{"foo":"bar"}', $data['INPUT']);
     // request 2
     $request = new Request(Request::METHOD_GET);
     $request->fromUrl($_SERVER['TEST_SERVER']);
     $response = new Response();
     $client->send($request, $response);
     $data = json_decode($response->getContent(), true);
     $this->assertEquals('GET', $data['SERVER']['REQUEST_METHOD']);
     $this->assertEmpty($data['INPUT']);
 }
开发者ID:kingsj,项目名称:core,代码行数:25,代码来源:FunctionalTest.php

示例11: setupAuth

 /**
  * @param Request $request
  */
 public function setupAuth(Request $request)
 {
     if ($auth = $this->getAuth()) {
         $request->addHeader('Authorization: Basic ' . base64_encode($auth->user . ':' . $auth->pass));
     }
 }
开发者ID:o100ja,项目名称:rug,代码行数:9,代码来源:Connector.php

示例12: addPsrHeadersToBuzzRequest

 /**
  * Apply headers on a Buzz request.
  *
  * @param RequestInterface $request
  * @param BuzzRequest      $buzzRequest
  */
 private function addPsrHeadersToBuzzRequest(RequestInterface $request, BuzzRequest $buzzRequest)
 {
     $headers = $request->getHeaders();
     foreach ($headers as $name => $values) {
         foreach ($values as $header) {
             $buzzRequest->addHeader($name . ': ' . $header);
         }
     }
 }
开发者ID:php-http,项目名称:buzz-adapter,代码行数:15,代码来源:Client.php

示例13: doRequest

 /**
  * @parem string  $controller
  * @param Request $request
  * @param array   $qs
  *
  * @throws RequestException
  *
  * @return JsonResponse
  */
 protected function doRequest($controller, Request $request, array $qs = array())
 {
     $request->fromUrl($this->getApiEndpoint($controller) . '?' . http_build_query($qs));
     $request->addHeader('Authorization: Basic ' . $this->options['key']);
     $request->addHeader('Accept: text/json');
     $this->client->send($request, $response = new JsonResponse());
     $content = $response->getContentJson(true);
     if (!in_array($content['ReturnCode'], array(self::EXECCODE_SUCCESS, self::EXECCODE_OPERATION_REFUSED))) {
         $e = new RequestException(print_r(array_merge($content, array('url' => $request->getUrl(), 'content' => $request->getContent())), true));
         $e->setRequest($request);
         throw $e;
     }
     return $response;
 }
开发者ID:winzou,项目名称:limonetik-php-api,代码行数:23,代码来源:APIClient.php

示例14: getGroupByID

 /**
  * @param $id
  * @return mixed|null
  */
 public function getGroupByID($id)
 {
     $token = $this->getAccessToken();
     if ($token == "") {
         return null;
     }
     $client = new Curl();
     $req = new Request(Request::METHOD_GET, "/" . $this->tenant . "/groups?api-version=1.6", "https://graph.windows.net");
     $req->addHeader("authorization: Bearer " . $token);
     $res = new Response();
     $client->setTimeout(20000);
     $client->send($req, $res);
     if ($res->getStatusCode() < 299) {
         return json_decode($res->getContent());
     }
     if ($res->getStatusCode() == 401) {
         $this->refreshToken($this->token->getToken()->getUser());
         return $this->getGroupByID($id);
     }
     return null;
 }
开发者ID:PhilippeGeek,项目名称:adhesion,代码行数:25,代码来源:Azure.php

示例15: 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;
 }
开发者ID:gte451f,项目名称:basecamp-api,代码行数:79,代码来源:Client.php


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