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


PHP HTTPClient::get方法代码示例

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


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

示例1: challenge

 /**
  * Send an HTTP GET to the notification handler with a
  * challenge string to see if it repsonds correctly.
  *
  * @param string $endpoint URL of the notification handler
  * @param string $feed     the feed being subscribed to
  *
  * @return boolean success
  */
 function challenge($endpoint, $feed)
 {
     $code = common_confirmation_code(128);
     $params = array('url' => $feed, 'challenge' => $code);
     $url = $endpoint . '?' . http_build_query($params);
     try {
         $client = new HTTPClient();
         $response = $client->get($url);
     } catch (HTTP_Request2_Exception $e) {
         common_log(LOG_INFO, 'RSSCloud plugin - failure testing notify handler ' . $endpoint . ' - ' . $e->getMessage());
         return false;
     }
     // Check response is betweet 200 and 299 and body contains challenge data
     $status = $response->getStatus();
     $body = $response->getBody();
     if ($status >= 200 && $status < 300) {
         // NOTE: the spec says that the body must contain the string
         // challenge.  It doesn't say that the body must contain the
         // challenge string ONLY, although that seems to be the way
         // the other implementors have interpreted it.
         if (strpos($body, $code) !== false) {
             common_log(LOG_INFO, 'RSSCloud plugin - ' . "success testing notify handler:  {$endpoint}");
             return true;
         } else {
             common_log(LOG_INFO, 'RSSCloud plugin - ' . 'challenge/repsonse failed for notify handler ' . $endpoint);
             common_debug('body = ' . var_export($body, true));
             return false;
         }
     } else {
         common_log(LOG_INFO, 'RSSCloud plugin - ' . "failure testing notify handler:  {$endpoint} " . ' - got HTTP ' . $status);
         common_debug('body = ' . var_export($body, true));
         return false;
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:43,代码来源:RSSCloudNotifier.php

示例2: testGetRequestIsUnsuccessful

 function testGetRequestIsUnsuccessful()
 {
     \VCR\VCR::insertCassette('gathercontent_get_me_failure.yml');
     $subject = new HTTPClient('invalid.user@example.com', 'bogus-api-key');
     $response = $subject->get('https://api.gathercontent.com/me', [], ['Accept: application/vnd.gathercontent.v0.5+json']);
     $this->assertNotEquals(200, $response->status);
     $this->assertEquals('Invalid credentials.', $response->body);
 }
开发者ID:vigetlabs,项目名称:gather-content-api,代码行数:8,代码来源:HTTPClientTest.php

示例3: checkUpdates

 public function checkUpdates(FeedSub $feedsub)
 {
     $request = new HTTPClient();
     $feed = $request->get($feedsub->uri);
     if (!$feed->isOk()) {
         throw new ServerException('FeedSub could not fetch id=' . $feedsub->id . ' (Error ' . $feed->getStatus() . ': ' . $feed->getBody());
     }
     $feedsub->receive($feed->getBody(), null);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:9,代码来源:feedpoll.php

示例4: fromHcardUrl

 static function fromHcardUrl($url)
 {
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($url);
     if (!$response->isOk()) {
         return null;
     }
     return self::hcardHints($response->getBody(), $response->getUrl());
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:10,代码来源:discoveryhints.php

示例5: _parseSvcDoc

 private function _parseSvcDoc()
 {
     $client = new HTTPClient();
     $response = $client->get($this->svcDocUrl);
     if ($response->getStatus() != 200) {
         throw new Exception("Can't get {$this->svcDocUrl}; response status " . $response->getStatus());
     }
     $xml = $response->getBody();
     $dom = new DOMDocument();
     // We don't want to bother with white spaces
     $dom->preserveWhiteSpace = false;
     // Don't spew XML warnings to output
     $old = error_reporting();
     error_reporting($old & ~E_WARNING);
     $ok = $dom->loadXML($xml);
     error_reporting($old);
     $path = new DOMXPath($dom);
     $path->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
     $path->registerNamespace('app', 'http://www.w3.org/2007/app');
     $path->registerNamespace('activity', 'http://activitystrea.ms/spec/1.0/');
     $collections = $path->query('//app:collection');
     for ($i = 0; $i < $collections->length; $i++) {
         $collection = $collections->item($i);
         $url = $collection->getAttribute('href');
         $takesEntries = false;
         $accepts = $path->query('app:accept', $collection);
         for ($j = 0; $j < $accepts->length; $j++) {
             $accept = $accepts->item($j);
             $acceptValue = $accept->nodeValue;
             if (preg_match('#application/atom\\+xml(;\\s*type=entry)?#', $acceptValue)) {
                 $takesEntries = true;
                 break;
             }
         }
         if (!$takesEntries) {
             continue;
         }
         $verbs = $path->query('activity:verb', $collection);
         if ($verbs->length == 0) {
             $this->_addCollection(ActivityVerb::POST, $url);
         } else {
             for ($k = 0; $k < $verbs->length; $k++) {
                 $verb = $verbs->item($k);
                 $this->_addCollection($verb->nodeValue, $url);
             }
         }
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:48,代码来源:activitysink.php

示例6: updateProfileURL

 /**
  * Look up and if necessary create an Ostatus_profile for the remote entity
  * with the given profile page URL. This should never return null -- you
  * will either get an object or an exception will be thrown.
  *
  * @param string $profile_url
  * @return Ostatus_profile
  * @throws Exception on various error conditions
  * @throws OStatusShadowException if this reference would obscure a local user/group
  */
 public static function updateProfileURL($profile_url, $hints = array())
 {
     $oprofile = null;
     $hints['profileurl'] = $profile_url;
     // Fetch the URL
     // XXX: HTTP caching
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($profile_url);
     if (!$response->isOk()) {
         // TRANS: Exception. %s is a profile URL.
         throw new Exception(sprintf(_('Could not reach profile page %s.'), $profile_url));
     }
     // Check if we have a non-canonical URL
     $finalUrl = $response->getUrl();
     if ($finalUrl != $profile_url) {
         $hints['profileurl'] = $finalUrl;
     }
     // Try to get some hCard data
     $body = $response->getBody();
     $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
     if (!empty($hcardHints)) {
         $hints = array_merge($hints, $hcardHints);
     }
     // Check if they've got an LRDD header
     $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
     try {
         $xrd = new XML_XRD();
         $xrd->loadFile($lrdd);
         $xrdHints = DiscoveryHints::fromXRD($xrd);
         $hints = array_merge($hints, $xrdHints);
     } catch (Exception $e) {
         // No hints available from XRD
     }
     // If discovery found a feedurl (probably from LRDD), use it.
     if (array_key_exists('feedurl', $hints)) {
         return self::ensureFeedURL($hints['feedurl'], $hints);
     }
     // Get the feed URL from HTML
     $discover = new FeedDiscovery();
     $feedurl = $discover->discoverFromHTML($finalUrl, $body);
     if (!empty($feedurl)) {
         $hints['feedurl'] = $feedurl;
         return self::ensureFeedURL($feedurl, $hints);
     }
     // TRANS: Exception. %s is a URL.
     throw new Exception(sprintf(_m('Could not find a feed URL for profile page %s.'), $finalUrl));
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:58,代码来源:update_ostatus_profiles.php

示例7: getTweetHtml

function getTweetHtml($url)
{
    try {
        $client = new HTTPClient();
        $response = $client->get($url);
    } catch (HTTP_Request2_Exception $e) {
        print "ERROR: HTTP response " . $e->getMessage() . "\n";
        return false;
    }
    if (!$response->isOk()) {
        print "ERROR: HTTP response " . $response->getCode() . "\n";
        return false;
    }
    $body = $response->getBody();
    return tweetHtmlFromBody($body);
}
开发者ID:microcosmx,项目名称:experiments,代码行数:16,代码来源:importtwitteratom.php

示例8: fetchUrl

 protected function fetchUrl($url, $method = HTTPClient::METHOD_GET)
 {
     $client = new HTTPClient();
     // GAAHHH, this method sucks! How about we make a better HTTPClient interface?
     switch ($method) {
         case HTTPClient::METHOD_GET:
             $response = $client->get($url);
             break;
         case HTTPClient::METHOD_HEAD:
             $response = $client->head($url);
             break;
         default:
             throw new Exception('Bad HTTP method.');
     }
     if ($response->getStatus() != 200) {
         throw new Exception('Unexpected HTTP status code.');
     }
     return $response;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:19,代码来源:lrddmethod.php

示例9: discoverFromURL

 /**
  * @param string $url
  * @param bool $htmlOk pass false here if you don't want to follow web pages.
  * @return string with validated URL
  * @throws FeedSubBadURLException
  * @throws FeedSubBadHtmlException
  * @throws FeedSubNoFeedException
  * @throws FeedSubEmptyException
  * @throws FeedSubUnrecognizedTypeException
  */
 function discoverFromURL($url, $htmlOk = true)
 {
     try {
         $client = new HTTPClient();
         $response = $client->get($url);
     } catch (HTTP_Request2_Exception $e) {
         common_log(LOG_ERR, __METHOD__ . " Failure for {$url} - " . $e->getMessage());
         throw new FeedSubBadURLException($e->getMessage());
     }
     if ($htmlOk) {
         $type = $response->getHeader('Content-Type');
         $isHtml = preg_match('!^(text/html|application/xhtml\\+xml)!i', $type);
         if ($isHtml) {
             $target = $this->discoverFromHTML($response->getUrl(), $response->getBody());
             if (!$target) {
                 throw new FeedSubNoFeedException($url);
             }
             return $this->discoverFromURL($target, false);
         }
     }
     return $this->initFromResponse($response);
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:32,代码来源:feeddiscovery.php

示例10: pageCount

 function pageCount()
 {
     $http = new HTTPClient();
     $ret = $http->get($this->index_url . '/text/_count');
     if ($ret !== false) {
         if (empty($this->json)) {
             $this->json = new Services_JSON();
         }
         $json = $this->json->decode($ret);
         return $json->count;
     }
     return false;
 }
开发者ID:ahastudio,项目名称:moniwiki,代码行数:13,代码来源:titleindexer.es.php

示例11: sendRegistration

 public static function sendRegistration($domain, $email, $access_key = '', $errors = '')
 {
     // Send data
     $link = SITEGUARDING_SERVER . '?action=register&type=json&data=';
     $data = array('domain' => $domain, 'email' => $email, 'access_key' => $access_key, 'errors' => $errors);
     $link .= base64_encode(json_encode($data));
     //$msg = trim(file_get_contents($link));
     include_once dirname(__FILE__) . '/HttpClient.class.php';
     $HTTPClient = new HTTPClient();
     $msg = $HTTPClient->get($link);
     if ($msg == '') {
         return true;
     } else {
         return $msg;
     }
 }
开发者ID:nhathong1204,项目名称:bdshungthinh,代码行数:16,代码来源:wp-antivirus-site-protection.php

示例12: setAvatar

 function setAvatar($user)
 {
     $picUrl = sprintf('http://graph.facebook.com/%s/picture?type=large', $this->fbuid);
     // fetch the picture from Facebook
     $client = new HTTPClient();
     // fetch the actual picture
     $response = $client->get($picUrl);
     if ($response->isOk()) {
         $finalUrl = $client->getUrl();
         // Make sure the filename is unique becuase it's possible for a user
         // to deauthorize our app, and then come back in as a new user but
         // have the same Facebook picture (avatar URLs have a unique index
         // and their URLs are based on the filenames).
         $filename = 'facebook-' . common_good_rand(4) . '-' . substr(strrchr($finalUrl, '/'), 1);
         $ok = file_put_contents(Avatar::path($filename), $response->getBody());
         if (!$ok) {
             common_log(LOG_WARNING, sprintf('Couldn\'t save Facebook avatar %s', $tmp), __FILE__);
         } else {
             // save it as an avatar
             $profile = $user->getProfile();
             if ($profile->setOriginal($filename)) {
                 common_log(LOG_INFO, sprintf('Saved avatar for %s (%d) from Facebook picture for ' . '%s (fbuid %d), filename = %s', $user->nickname, $user->id, $this->fbuser['name'], $this->fbuid, $filename), __FILE__);
             }
         }
     }
 }
开发者ID:harriewang,项目名称:InnertieWebsite,代码行数:26,代码来源:facebookfinishlogin.php

示例13: verify

 /**
  * Send a verification ping to subscriber, and if confirmed apply the changes.
  * This may create, update, or delete the database record.
  *
  * @param string $mode 'subscribe' or 'unsubscribe'
  * @param string $token hub.verify_token value, if provided by client
  * @throws ClientException on failure
  */
 function verify($mode, $token = null)
 {
     assert($mode == 'subscribe' || $mode == 'unsubscribe');
     $challenge = common_random_hexstr(32);
     $params = array('hub.mode' => $mode, 'hub.topic' => $this->topic, 'hub.challenge' => $challenge);
     if ($mode == 'subscribe') {
         $params['hub.lease_seconds'] = $this->lease;
     }
     if ($token !== null) {
         // TODO: deprecated in PuSH 0.4
         $params['hub.verify_token'] = $token;
         // let's put it in there if remote uses PuSH <0.4
     }
     // Any existing query string parameters must be preserved
     $url = $this->callback;
     if (strpos($url, '?') !== false) {
         $url .= '&';
     } else {
         $url .= '?';
     }
     $url .= http_build_query($params, '', '&');
     $request = new HTTPClient();
     $response = $request->get($url);
     $status = $response->getStatus();
     if ($status >= 200 && $status < 300) {
         common_log(LOG_INFO, "Verified {$mode} of {$this->callback}:{$this->topic}");
     } else {
         // TRANS: Client exception. %s is a HTTP status code.
         throw new ClientException(sprintf(_m('Hub subscriber verification returned HTTP %s.'), $status));
     }
     $old = HubSub::getByHashkey($this->topic, $this->callback);
     if ($mode == 'subscribe') {
         if ($old instanceof HubSub) {
             $this->update($old);
         } else {
             $ok = $this->insert();
         }
     } else {
         if ($mode == 'unsubscribe') {
             if ($old instanceof HubSub) {
                 $old->delete();
             } else {
                 // That's ok, we're already unsubscribed.
             }
         }
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:55,代码来源:HubSub.php

示例14: setAvatar

 function setAvatar($user)
 {
     try {
         $picUrl = sprintf('http://graph.facebook.com/%d/picture?type=large', $this->fbuser->id);
         // fetch the picture from Facebook
         $client = new HTTPClient();
         // fetch the actual picture
         $response = $client->get($picUrl);
         if ($response->isOk()) {
             // seems to always be jpeg, but not sure
             $tmpname = "facebook-avatar-tmp-" . common_random_hexstr(4);
             $ok = file_put_contents(Avatar::path($tmpname), $response->getBody());
             if (!$ok) {
                 common_log(LOG_WARNING, 'Couldn\'t save tmp Facebook avatar: ' . $tmpname, __FILE__);
             } else {
                 // save it as an avatar
                 $imagefile = new ImageFile(null, Avatar::path($tmpname));
                 $filename = Avatar::filename($user->id, image_type_to_extension($imagefile->preferredType()), 180, common_timestamp());
                 // Previous docs said 180 is the "biggest img we get from Facebook"
                 $imagefile->resizeTo(Avatar::path($filename, array('width' => 180, 'height' => 180)));
                 // No need to keep the temporary file around...
                 @unlink(Avatar::path($tmpname));
                 $profile = $user->getProfile();
                 if ($profile->setOriginal($filename)) {
                     common_log(LOG_INFO, sprintf('Saved avatar for %s (%d) from Facebook picture for ' . '%s (fbuid %d), filename = %s', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid, $filename), __FILE__);
                     // clean up tmp file
                 }
             }
         }
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'Couldn\'t save Facebook avatar: ' . $e->getMessage(), __FILE__);
         // error isn't fatal, continue
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:34,代码来源:facebookfinishlogin.php

示例15: ensureProfileURL

 /**
  * Look up and if necessary create an Ostatus_profile for the remote entity
  * with the given profile page URL. This should never return null -- you
  * will either get an object or an exception will be thrown.
  *
  * @param string $profile_url
  * @return Ostatus_profile
  * @throws Exception on various error conditions
  * @throws OStatusShadowException if this reference would obscure a local user/group
  */
 public static function ensureProfileURL($profile_url, $hints = array())
 {
     $oprofile = self::getFromProfileURL($profile_url);
     if (!empty($oprofile)) {
         return $oprofile;
     }
     $hints['profileurl'] = $profile_url;
     // Fetch the URL
     // XXX: HTTP caching
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($profile_url);
     if (!$response->isOk()) {
         throw new Exception("Could not reach profile page: " . $profile_url);
     }
     // Check if we have a non-canonical URL
     $finalUrl = $response->getUrl();
     if ($finalUrl != $profile_url) {
         $hints['profileurl'] = $finalUrl;
         $oprofile = self::getFromProfileURL($finalUrl);
         if (!empty($oprofile)) {
             return $oprofile;
         }
     }
     // Try to get some hCard data
     $body = $response->getBody();
     $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
     if (!empty($hcardHints)) {
         $hints = array_merge($hints, $hcardHints);
     }
     // Check if they've got an LRDD header
     $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
     if (!empty($lrdd)) {
         $xrd = Discovery::fetchXrd($lrdd);
         $xrdHints = DiscoveryHints::fromXRD($xrd);
         $hints = array_merge($hints, $xrdHints);
     }
     // If discovery found a feedurl (probably from LRDD), use it.
     if (array_key_exists('feedurl', $hints)) {
         return self::ensureFeedURL($hints['feedurl'], $hints);
     }
     // Get the feed URL from HTML
     $discover = new FeedDiscovery();
     $feedurl = $discover->discoverFromHTML($finalUrl, $body);
     if (!empty($feedurl)) {
         $hints['feedurl'] = $feedurl;
         return self::ensureFeedURL($feedurl, $hints);
     }
     throw new Exception("Could not find a feed URL for profile page " . $finalUrl);
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:60,代码来源:Ostatus_profile.php


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