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


PHP Client::head方法代码示例

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


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

示例1: head

 /**
  * Performs an HTTP HEAD on a URI. $this->responseText and $this->responseObj
  * empty after this call, but you can read the content-length from
  * $this->responseLength.
  *
  * @param string $uri
  * @param string $accept_mime_type
  * @param array $custom_headers
  * @param array $options
  */
 public function head($uri = null, $accept_mime_type = 'application/json; charset=utf-8', array $custom_headers = array(), array $options = array())
 {
     $headers = array('accept' => $accept_mime_type);
     foreach ($custom_headers as $key => $value) {
         $headers[strtolower($key)] = $value;
     }
     $request = $this->client->head($uri, $headers, $options);
     $this->exec($request);
 }
开发者ID:nevetS,项目名称:flame,代码行数:19,代码来源:APIObject.php

示例2: fetch

 /**
  * @return mixed
  * @throws SummonException
  * @throws \Guzzle\Http\Exception\ClientErrorResponseException
  */
 public function fetch()
 {
     try {
         $response = $this->client->head()->send();
     } catch (ClientErrorResponseException $e) {
         // HEAD method is not allowed, try GET instead
         $response = $this->client->get()->send();
     }
     // update the url to the actual endpoint (after redirects)
     $this->url = $response->getInfo('url');
     list($this->mimetype) = explode(';', $response->getContentType());
     $type = self::getType($this->mimetype);
     $handler = sprintf('parse%s', ucfirst($type));
     if (!method_exists($this, $handler)) {
         throw new SummonException("Unable to handle type [{$type}] in self");
     }
     return $this->{$handler}($response);
 }
开发者ID:phindmarsh,项目名称:summon,代码行数:23,代码来源:Summon.php

示例3: resolveUrl

 public function resolveUrl($url)
 {
     $client = new GuzzleClient($url);
     $history = new HistoryPlugin();
     $client->addSubscriber($history);
     $response = $client->head($url)->send();
     if (!$response->isSuccessful()) {
         throw new \Exception(sprintf("Url %s is not a valid URL or website is down.", $url));
     }
     return $response->getEffectiveUrl();
 }
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe-social,代码行数:11,代码来源:FBUpdate.php

示例4: createComposerLockBadge

 /**
  * @param string $repository
  * @param string $format
  *
  * @return \PUGX\Badge\Model\Badge
  */
 public function createComposerLockBadge($repository, $format = 'svg')
 {
     $repo = str_replace('.git', '', $this->packageRepository->fetchByRepository($repository)->getOriginalObject()->getRepository());
     $request = $this->client->head($repo . '/blob/master/composer.lock', array(), array('timeout' => 2, 'connect_timeout' => 1, 'exceptions' => false));
     $response = $this->client->send($request);
     $status = 500;
     if ($request) {
         $status = $response->getStatusCode();
     }
     $this->text = self::LOCK_ERROR;
     $color = self::COLOR_ERROR;
     $subject = self::SUBJECT_ERROR;
     if (200 === $status) {
         $this->text = self::LOCK_COMMITTED;
         $color = self::COLOR_COMMITTED;
         $subject = self::SUBJECT;
     } elseif (404 === $status) {
         $this->text = self::LOCK_UNCOMMITTED;
         $color = self::COLOR_UNCOMMITTED;
         $subject = self::SUBJECT;
     }
     return $this->createBadgeFromRepository($repository, $subject, $color, $format);
 }
开发者ID:pugx,项目名称:badge-poser,代码行数:29,代码来源:CreateComposerLockBadge.php

示例5: validate

 public function validate($value, Constraint $constraint)
 {
     if (empty($value)) {
         return;
     }
     $previousViolationsCount = $this->context->getViolations()->count();
     parent::validate($value, $constraint);
     if ($previousViolationsCount < $this->context->getViolations()->count()) {
         return;
     }
     $client = new Client();
     try {
         $request = $client->head($value);
         $response = $request->send();
         if (!$response->isSuccessful()) {
             $this->context->addViolation($constraint->clientError, array('%errorCode%' => $response->getStatusCode()));
         }
     } catch (CurlException $e) {
         $this->context->addViolation($constraint->websiteDoesntExist, array('%url' => $value));
     } catch (ClientErrorResponseException $e) {
         $errorCode = $e->getResponse()->getStatusCode();
         if ($errorCode == 403) {
             $this->context->addViolation($constraint->accessDenied);
         } elseif ($errorCode == 404) {
             $this->context->addViolation($constraint->resNotFound);
         } elseif ($errorCode == 405) {
             $allow = $e->getResponse()->getHeaders()['allow'];
             if (!preg_match('#GET#', $allow)) {
                 $this->context->addViolation($constraint->methodNotAllowed);
             }
         } else {
             $this->context->addViolation($constraint->clientError, array('%errorCode%' => $errorCode));
         }
     } catch (ServerErrorResponseException $e) {
         $this->context->addViolation($constraint->serverError, array('%errorCode%' => $e->getResponse()->getStatusCode()));
     }
 }
开发者ID:claroline,项目名称:distribution,代码行数:37,代码来源:ReachableUrlValidator.php

示例6: testProperlyBlocksBasedOnRequestsInScope

 /**
  * @covers Guzzle\Http\Curl\CurlMulti
  */
 public function testProperlyBlocksBasedOnRequestsInScope()
 {
     $this->getServer()->flush();
     $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest1", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest2", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest3", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest4", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest5", "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\ntest6", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
     $client = new Client($this->getServer()->getUrl());
     $requests = array($client->get(), $client->get(), $client->get());
     // Sends 2 new requests in the middle of a CurlMulti loop while other requests
     // are completing.  This causes the scope of the multi handle to go up.
     $callback = function (Event $event) use($client) {
         $client->getConfig()->set('called', $client->getConfig('called') + 1);
         $request = $client->get();
         if ($client->getConfig('called') <= 2) {
             $request->getEventDispatcher()->addListener('request.complete', function (Event $event) use($client) {
                 $client->head()->send();
             });
         }
         $request->send();
     };
     $requests[0]->getEventDispatcher()->addListener('request.complete', $callback);
     $requests[1]->getEventDispatcher()->addListener('request.complete', $callback);
     $requests[2]->getEventDispatcher()->addListener('request.complete', $callback);
     $client->send($requests);
     $this->assertEquals(8, count($this->getServer()->getReceivedRequests(false)));
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:27,代码来源:CurlMultiTest.php

示例7: head

 /**
  * @param string $uri
  * @param array $headers
  * @param array $options
  * @return \Guzzle\Http\Message\RequestInterface
  */
 public function head($uri, $headers = null, $options = [])
 {
     $this->request = $this->client->head($uri, $headers, $options);
     $this->response = $this->request->send();
     return $this->response;
 }
开发者ID:chilimatic,项目名称:database-component,代码行数:12,代码来源:Connection.php

示例8: testHeadCanUseOptions

 public function testHeadCanUseOptions()
 {
     $client = new Client();
     $head = $client->head('http://www.foo.com', array(), array('query' => array('foo' => 'bar')));
     $this->assertEquals('bar', $head->getQuery()->get('foo'));
 }
开发者ID:carlesgutierrez,项目名称:libreobjet.org,代码行数:6,代码来源:ClientTest.php

示例9: testUriArrayAllowsCustomTemplateVariables

 /**
  * @covers Guzzle\Http\Client::createRequest
  * @covers Guzzle\Http\Client::get
  * @covers Guzzle\Http\Client::put
  * @covers Guzzle\Http\Client::post
  * @covers Guzzle\Http\Client::head
  * @covers Guzzle\Http\Client::options
  */
 public function testUriArrayAllowsCustomTemplateVariables()
 {
     $client = new Client();
     $vars = array('var' => 'hi');
     $this->assertEquals('/hi', (string) $client->createRequest('GET', array('/{var}', $vars))->getUrl());
     $this->assertEquals('/hi', (string) $client->get(array('/{var}', $vars))->getUrl());
     $this->assertEquals('/hi', (string) $client->put(array('/{var}', $vars))->getUrl());
     $this->assertEquals('/hi', (string) $client->post(array('/{var}', $vars))->getUrl());
     $this->assertEquals('/hi', (string) $client->head(array('/{var}', $vars))->getUrl());
     $this->assertEquals('/hi', (string) $client->options(array('/{var}', $vars))->getUrl());
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:19,代码来源:ClientTest.php

示例10: getRemoteFileSize

 /**
  * @param string $location
  * @return int
  */
 private function getRemoteFileSize($location)
 {
     $parts = parse_url($location);
     $http = new HttpClient($parts['scheme'] . '://' . $parts['host']);
     $response = $http->head($parts['path'])->send();
     return (int) current($response->getHeader('Content-Length')->toArray());
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:11,代码来源:S3.php


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