當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。