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


PHP Response::getHeaderLine方法代码示例

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


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

示例1: testCanConstructWithHeadersAsArray

 public function testCanConstructWithHeadersAsArray()
 {
     $r = new Response(200, ['Foo' => ['baz', 'bar']]);
     $this->assertSame(['Foo' => ['baz', 'bar']], $r->getHeaders());
     $this->assertSame('baz, bar', $r->getHeaderLine('Foo'));
     $this->assertSame(['baz', 'bar'], $r->getHeader('Foo'));
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:7,代码来源:ResponseTest.php

示例2: retryDecider

 static function retryDecider($retries, Request $request, Response $response = null, RequestException $exception = null)
 {
     // Limit the number of retries to 5
     if ($retries >= 5) {
         return false;
     }
     // Retry connection exceptions
     if ($exception instanceof ConnectException) {
         return true;
     }
     if ($response) {
         // Retry on server errors
         if ($response->getStatusCode() >= 500) {
             return true;
         }
         // Retry on rate limits
         if ($response->getStatusCode() == 429) {
             $retryDelay = $response->getHeaderLine('Retry-After');
             if (strlen($retryDelay)) {
                 printf(" retry delay: %d secs\n", (int) $retryDelay);
                 sleep((int) $retryDelay);
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:andig,项目名称:spotify-web-api-extensions,代码行数:27,代码来源:GuzzleClientFactory.php

示例3: hasExpectedResponse

 /**
  * Check if we got an expected response
  * 
  * @param Node     $node
  * @param Response $response
  * @return boolean
  */
 protected function hasExpectedResponse(Node $node, Response $response)
 {
     $status = $response->getStatusCode();
     $contentType = preg_replace('/\\s*;.*$/', '', $response->getHeaderLine('Content-Type'));
     if ($status == 404) {
         return false;
     } elseif ($status >= 300 || !in_array($contentType, ['application/json', 'text/plain'])) {
         $url = $this->getUrl($node);
         if ($contentType === 'text/plain') {
             $message = $response->getBody();
         } else {
             $message = "Server responded with a {$status} status and {$contentType}";
         }
         trigger_error("Failed to fetch '{$url}': {$message}", E_USER_WARNING);
         return false;
     }
     return true;
 }
开发者ID:legalthings,项目名称:data-enricher,代码行数:25,代码来源:Http.php

示例4: testCanSetHeaderAsArray

 public function testCanSetHeaderAsArray()
 {
     $r = new Response(200, ['foo' => ['baz ', ' bar ']]);
     $this->assertEquals('baz, bar', $r->getHeaderLine('foo'));
     $this->assertEquals(['baz', 'bar'], $r->getHeader('foo'));
 }
开发者ID:shomimn,项目名称:builder,代码行数:6,代码来源:ResponseTest.php

示例5: getCsrftoken

 /**
  * Get X-CSRFToken from Guzzle response
  *
  * @param \GuzzleHttp\Psr7\Response $response
  * @return mixed
  * @throws \InstagramWrapper\InstagramException
  */
 protected function getCsrftoken(Response $response)
 {
     $cookies_string = $response->getHeaderLine('set-cookie');
     preg_match("/csrftoken=(.*?);/", $cookies_string, $csrftoken_raw);
     if (empty($csrftoken_raw[1])) {
         throw new InstagramException("Can't get csrftoken from response");
     }
     $csrftoken = $csrftoken_raw[1];
     return $csrftoken;
 }
开发者ID:moelius,项目名称:instagram-wrapper,代码行数:17,代码来源:WebClient.php

示例6: getSolrErrorMessage

 /**
  * Attempt to extract a Solr error message from a response.
  *
  * @param  Response $response The response.
  * @return string Error message or NULL if not found.
  */
 private function getSolrErrorMessage(Response $response)
 {
     // Try to get the SOLR error message from the response body
     $contentType = $response->getHeaderLine("Content-Type");
     $content = $response->getBody()->getContents();
     // If response contains XML
     if (strpos($contentType, 'application/xml') !== false) {
         return $this->getXmlError($content);
     }
     // If response contains JSON
     if (strpos($contentType, 'application/json') !== false) {
         return $this->getJsonError($content);
     }
     // Message not found
     return null;
 }
开发者ID:opendi,项目名称:solrclient,代码行数:22,代码来源:Client.php

示例7: header

 /**
  * Get HTTP header.
  *
  * @param $key
  * @param mixed $default
  *
  * @return mixed
  */
 public function header($key, $default = null)
 {
     return $this->response->hasHeader($key) ? $this->response->getHeaderLine($key) : $default;
 }
开发者ID:bugotech,项目名称:rfm,代码行数:12,代码来源:Response.php

示例8: body

 /**
  * @return mixed
  */
 public function body(Response $response)
 {
     $type = $response->getHeaderLine('Content-Type');
     if (false === strpos($type, 'application/json')) {
         throw new \RuntimeException(sprintf('Invalid response type `%s` detected', $type));
     }
     $body = (string) $response->getBody();
     return json_decode($body, true);
 }
开发者ID:shadowhand,项目名称:radiotide,代码行数:12,代码来源:TidalClient.php

示例9: extractArguments

 /**
  * 从响应中提取需要catch的参数
  * @param Examination $examination
  * @param Response $response
  * @return bool
  * @throws InvalidArgumentException
  */
 protected function extractArguments(Examination $examination, Response $response)
 {
     $catch = $examination->getCatch();
     if (empty($catch)) {
         return true;
     }
     //从header里面提取
     if (isset($catch['header']) && is_array($catch['header'])) {
         foreach ($catch['header'] as $parameter => $name) {
             if (is_numeric($parameter)) {
                 $newArgumentName = $name;
                 $oldArgumentName = $name;
             } else {
                 $newArgumentName = $name;
                 $oldArgumentName = $parameter;
             }
             $this->arguments->set($newArgumentName, $response->getHeaderLine($oldArgumentName));
         }
     }
     //从body里面提取
     if (isset($catch['body']) && is_array($catch['body'])) {
         $json = json_decode($response->getBody(), true);
         if (json_last_error() != JSON_ERROR_NONE) {
             throw new InvalidArgumentException(sprintf("Invalid Json Format"));
         }
         foreach ($catch['body'] as $parameter => $name) {
             if (is_numeric($parameter)) {
                 $newArgumentName = $name;
                 $oldArgumentName = $name;
             } else {
                 $newArgumentName = $name;
                 $oldArgumentName = $parameter;
             }
             $this->arguments->set($newArgumentName, Hash::get($json, $oldArgumentName));
         }
     }
     return true;
 }
开发者ID:slince,项目名称:runner,代码行数:45,代码来源:Runner.php


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