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


PHP Response::getHeader方法代码示例

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


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

示例1: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:42,代码来源:Guzzle.php

示例2: detectEncoding

 /**
  * @return string
  */
 protected function detectEncoding()
 {
     $encoding = '';
     $contentType = $this->response->getHeader('Content-Type');
     if ($contentType != '' && strpos($contentType, 'charset') !== FALSE) {
         $encoding = $this->detectEncodingOutOfContentTypeString($contentType);
     }
     if ($encoding === '' && $this->detectMimeType() === 'text/html') {
         $encoding = $this->extractContentTypeStringOutOfMetaTag();
     }
     return $encoding != '' ? strtoupper(trim($encoding)) : $this->defaultEncoding;
 }
开发者ID:morphodo,项目名称:crawler-bundle,代码行数:15,代码来源:DocumentBuilder.php

示例3: verifyHttpResponseHash

 protected function verifyHttpResponseHash(Response $httpResponse)
 {
     $hash = $httpResponse->getHeader('hash');
     $responseData = $httpResponse->getBody(true);
     $validHash = $this->getHMACMD5Hash($this->getSecret(), $responseData);
     $isValid = $validHash == $hash;
     return $isValid;
 }
开发者ID:phpcommerce,项目名称:payment-giropay,代码行数:8,代码来源:GiropayResponseGeneratorImpl.php

示例4: __construct

 /**
  * Response constructor
  *
  * @param  HttpResponse $httpResponse
  * @return self
  */
 public function __construct(HttpResponse $httpResponse)
 {
     if (stripos($httpResponse->getHeader('Content-Type'), 'text/javascript') !== false) {
         $this->_response = $this->processJson($httpResponse->getBody());
     } else {
         $this->_response = $this->processXml($httpResponse->getBody());
     }
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:14,代码来源:Response.php

示例5: parse

 public function parse(Response $response)
 {
     $collection = new Collection();
     if (!$response->getBody()) {
         return $collection;
     }
     // help bad responses be more multipart compliant
     $body = "\r\n" . $response->getBody()->__toString() . "\r\n";
     // multipart
     preg_match('/boundary\\=\\"(.*?)\\"/', $response->getHeader('Content-Type'), $matches);
     if (isset($matches[1])) {
         $boundary = $matches[1];
     } else {
         preg_match('/boundary\\=(.*?)(\\s|$|\\;)/', $response->getHeader('Content-Type'), $matches);
         $boundary = $matches[1];
     }
     // strip quotes off of the boundary
     $boundary = preg_replace('/^\\"(.*?)\\"$/', '\\1', $boundary);
     // clean up the body to remove a reamble and epilogue
     $body = preg_replace('/^(.*?)\\r\\n--' . $boundary . '\\r\\n/', "\r\n--{$boundary}\r\n", $body);
     // make the last one look like the rest for easier parsing
     $body = preg_replace('/\\r\\n--' . $boundary . '--/', "\r\n--{$boundary}\r\n", $body);
     // cut up the message
     $multi_parts = explode("\r\n--{$boundary}\r\n", $body);
     // take off anything that happens before the first boundary (the preamble)
     array_shift($multi_parts);
     // take off anything after the last boundary (the epilogue)
     array_pop($multi_parts);
     $message_parser = new MessageParser();
     $parser = new Single();
     // go through each part of the multipart message
     foreach ($multi_parts as $part) {
         // get Guzzle to parse this multipart section as if it's a whole HTTP message
         $parts = $message_parser->parseResponse("HTTP/1.1 200 OK\r\n" . $part);
         // now throw this single faked message through the Single GetObject response parser
         $single = new Response($parts['code'], $parts['headers'], Stream::factory($parts['body']));
         $obj = $parser->parse($single);
         // add information about this multipart to the returned collection
         $collection->push($obj);
     }
     return $collection;
 }
开发者ID:callcolor,项目名称:PHRETS,代码行数:42,代码来源:Multiple.php

示例6: parseResponse

 /**
  * Parse the returned response.
  *
  * @param  \GuzzleHttp\Message\Response  $response
  * @return array
  *
  * @throws \RuntimeException
  */
 protected function parseResponse(Response $response)
 {
     $contentType = explode(';', $response->getHeader('content-type'))[0];
     switch ($contentType) {
         case 'text/javascript':
         case 'application/json':
             return $response->json();
         case 'application/xml':
             return $response->xml();
     }
     throw new \RuntimeException("Unsupported returned content-type [{$contentType}]");
 }
开发者ID:pcextreme,项目名称:cloudstack-client,代码行数:20,代码来源:CloudstackConnector.php

示例7: handleResponse

 /**
  * @param \GuzzleHttp\Message\Response $response
  * @return Error
  */
 protected function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response
         return new Error($response->getStatusCode(), $json['code'], $json['message']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosign,代码行数:17,代码来源:Guzzle.php

示例8: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     if (preg_match('/\\<meta[^\\>]+http-equiv="refresh" content=".*?url=(.*?)"/i', $response->getBody(true), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     if (preg_match('~url=(.*)~', (string) $response->getHeader('Refresh'), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:aleguisf,项目名称:fvdev1,代码行数:29,代码来源:Guzzle.php

示例9: handleResponse

 /**
  * @param Response $response
  * @return array|mixed
  * @throws JsonApiResponseException
  */
 public function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     // if its not json, then just return the response and handle it in your own object.
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     // adobe says hey this didn't work!
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response, from Adobe complaining about something in your code.
         throw new JsonApiResponseException($response->getStatusCode(), $json['message'], $json['code']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosignv3,代码行数:20,代码来源:GuzzleTransport.php

示例10: evaluateResponse

 public function evaluateResponse(Response $response)
 {
     $errors = [];
     try {
         // Test response code
         if (array_key_exists('response.statusCode', $this->expectations)) {
             $this->expectations['response.statusCode']->evaluate((int) $response->getStatusCode(), 'Status code was expected to be `%s` but was actually `' . $response->getStatusCode() . '`');
         }
     } catch (AssertionFailedException $e) {
         $errors[] = $e->getMessage();
     }
     // Test headers
     foreach ($this->expectations as $name => $expectation) {
         try {
             if (substr($name, 0, 8) === 'headers.') {
                 $headerName = substr($name, 8);
                 $headerValue = $response->getHeader($headerName);
                 $this->expectations['headers.' . strtolower($headerName)]->evaluate($headerValue, 'Header `' . $headerName . '` expected to be `%s` but was `%s`');
             }
         } catch (AssertionFailedException $e) {
             $errors[] = $e->getMessage();
         }
     }
     // Test body
     $body = json_decode($response->getBody(), true);
     foreach ($this->expectations as $name => $expectation) {
         try {
             if (substr($name, 0, 5) === 'body.') {
                 $keyName = substr($name, 5);
                 $keyValue = array_get($body, $keyName);
                 $this->expectations['body.' . strtolower($keyName)]->evaluate($keyValue, 'Body key `' . $keyName . '` expected to be `%s` but was `%s`');
             }
         } catch (AssertionFailedException $e) {
             $errors[] = $e->getMessage();
         }
     }
     return $errors;
 }
开发者ID:alexbilbie,项目名称:fizzfuzz,代码行数:38,代码来源:Payload.php

示例11: setResponseStream

 private function setResponseStream(Response $response, $socket, EmitterInterface $emitter, $useFilter = false)
 {
     if ($response->getHeader('Transfer-Encoding') == "chunked") {
         stream_filter_append($socket, 'dechunk');
     }
     // Attach filter
     if ($useFilter) {
         stream_filter_append($socket, 'event', STREAM_FILTER_READ, ['emitter' => $emitter, 'content_type' => $response->getHeader('Content-Type')]);
     }
     $stream = new Stream($socket);
     $response->setBody($stream);
 }
开发者ID:schmunk42,项目名称:docker-php,代码行数:12,代码来源:DockerAdapter.php

示例12: getHeader

 /**
  * @param $key
  * @return string
  */
 public function getHeader($key)
 {
     return $this->response->getHeader($key);
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:8,代码来源:response.php

示例13: getHeader

 /**
  * Fetch a named header.
  *
  * @param string $name
  *
  * @return string|null
  */
 public function getHeader($name)
 {
     return $this->response->getHeader($name);
 }
开发者ID:ubermichael,项目名称:pkppln-php,代码行数:11,代码来源:PingResult.php

示例14: setResponseStream

 private function setResponseStream(Response $response, $socket)
 {
     if ($response->getHeader('Transfer-Encoding') == "chunked") {
         $stream = new ChunkedStream($socket);
     } elseif ($response->getHeader('Content-Type') == "application/vnd.docker.raw-stream") {
         $stream = new AttachStream($socket);
     } else {
         $stream = new Stream($socket);
     }
     $response->setBody($stream);
 }
开发者ID:matgou,项目名称:docker-php,代码行数:11,代码来源:DockerAdapter.php

示例15: detectType

 private function detectType(\GuzzleHttp\Message\Response $response)
 {
     switch ($response->getHeader('content-type')) {
         case 'application/json':
             return $response->json();
             break;
         case 'application/xml':
         case 'text/xml':
             return json_decode(json_encode($response->xml()), true);
             break;
         default:
             return $response->getBody();
     }
 }
开发者ID:skizu,项目名称:simpleapi,代码行数:14,代码来源:RegisterAPI.php


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