本文整理汇总了PHP中HttpClient::get方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::get方法的具体用法?PHP HttpClient::get怎么用?PHP HttpClient::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crawlerProgramItems
static function crawlerProgramItems($date, $chnnel)
{
$url = replaceStr(CnTVLiveParse::BASE_EPISODE, '{DATE}', $date);
$url = replaceStr($url, '{TV_CODE}', $chnnel);
$client = new HttpClient('tv.cntv.cn');
$client->get('/epg');
$client->get($url);
writetofile("program_live_item_crawler.log", "url:[http://tv.cntv.cn" . $url . "]");
$content = $client->getContent();
return CnTVLiveParse::parseMovieInfoByContent($content, $p_code, $type);
}
示例2: download
/**
* @param Url $url
*
* @return File
* @throws DownloadFailedException
*/
public function download(Url $url)
{
$this->output->writeInfo(sprintf('Downloading %s', $url));
$response = $this->curl->get($url);
if ($response->getHttpCode() !== 200) {
throw new DownloadFailedException(sprintf('Download failed (HTTP status code %s) %s', $response->getHttpCode(), $response->getErrorMessage()));
}
if (empty($response->getBody())) {
throw new DownloadFailedException('Download failed - response is empty');
}
return new File($this->getFilename($url), $response->getBody());
}
示例3: download
/**
* @param string $keyId
*
* @return string
* @throws DownloadFailedException
*/
public function download($keyId)
{
$params = ['search' => '0x' . $keyId, 'op' => 'get', 'options' => 'mr'];
foreach ($this->keyServers as $keyServer) {
$this->output->writeInfo(sprintf('Trying %s', $keyServer));
$result = $this->httpClient->get(new Url($keyServer . self::PATH), $params);
if ($result->getHttpCode() == 200) {
$this->output->writeInfo('Sucessfully downloaded key');
return $result->getBody();
}
$this->output->writeWarning(sprintf('Failed with status code %s: %s', $result->getHttpCode(), $result->getErrorMessage()));
}
throw new DownloadFailedException(sprintf('Key %s not found on key servers', $keyId));
}
示例4: testEffectiveUrl
/**
* @dataProvider effectiveUrls
*/
public function testEffectiveUrl($url, $expected, $params = array())
{
$http = new HttpClient();
$http->get($url, $params);
$this->assertEquals($expected, $http->getEffectiveUrl());
$this->assertEquals($expected, $http->effectiveUrl);
}
示例5: http_get_file
function http_get_file($url)
{
$httpClient = new HttpClient("epub.cnki.net");
$httpClient->get($url);
$content = $httpClient->getContent();
return $content;
}
示例6: fetch
/**
* Uses httpClient to fetch results and map to an object of type $className
*
* @param string $url
* @param string $className
* @return obj
*/
private function fetch($url, $className)
{
$key = sha1($url);
if (!isset($this->cache[$key])) {
$xml = $this->httpClient->get($url);
$this->cache[$key] = call_user_func_array(array($className, 'createFromXml'), array($xml, $this));
}
return $this->cache[$key];
}
示例7: processFeed
/**
* @param Feed $feed
*/
public function processFeed($feed)
{
$http = new \HttpClient();
$body = $http->get($this->url);
if ($body !== false) {
$this->parseBody($body, $feed);
} elseif ($this->showErrors) {
$feed->addItem(['title' => $http->lastError, 'link' => $this->url]);
}
}
示例8: HttpClient
function _loadVersion()
{
require_once JPATH_COMPONENT . DS . 'libraries' . DS . 'httpclient.class.php';
$client = new HttpClient('www.easy-joomla.org');
if (!$client->get('/components/com_versions/directinfo.php?catid=3')) {
$this->setError($client->getError());
return false;
}
$this->_current = $client->getContent();
return true;
}
示例9: download
/**
* download a media
* @param string $filename - file for downloading to
* @param string $mediaId - mediaId of file
* @param bool $https(optional default true) - if downloading video-type file,
* set $https to false for http request
* @return int - filesize of the media or string - json for error message(if error)
*/
public function download($filename, $mediaId, $https = true)
{
if ($https) {
$client = new HttpClient("https://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
} else {
$client = new HttpClient("http://api.weixin.qq.com/cgi-bin/media/get?access_token={$this->access_token}&media_id={$mediaId}");
}
$client->get();
if ($client->getState() == 200) {
if (!is_null(json_decode($client->getResponse()))) {
//data of json format(error here)
return $client->getResponse();
} else {
file_put_contents($filename, $client->getResponse());
return filesize($filename);
}
} else {
return false;
}
}
示例10: fixProfile
function fixProfile($uri)
{
$oprofile = Ostatus_profile::getKV('uri', $uri);
if (!$oprofile) {
print "No OStatus remote profile known for URI {$uri}\n";
return false;
}
echo "Before:\n";
showProfileInfo($oprofile);
$feedurl = $oprofile->feeduri;
$client = new HttpClient();
$response = $client->get($feedurl);
if ($response->isOk()) {
echo "Updating profile from feed: {$feedurl}\n";
$dom = new DOMDocument();
if ($dom->loadXML($response->getBody())) {
$feed = $dom->documentElement;
$entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
if ($entries->length) {
$entry = $entries->item(0);
$activity = new Activity($entry, $feed);
$oprofile->checkAuthorship($activity);
echo " (ok)\n";
} else {
echo " (no entry; skipping)\n";
return false;
}
} else {
echo " (bad feed; skipping)\n";
return false;
}
} else {
echo "Failed feed fetch: {$response->getStatus()} for {$feedurl}\n";
return false;
}
echo "After:\n";
showProfileInfo($oprofile);
return true;
}
示例11: checkPass
/**
* Preferences are handled in _PassUser
*/
function checkPass($password)
{
$userid = $this->_userid;
if (!loadPhpExtension('openssl')) {
trigger_error(sprintf(_("The PECL %s extension cannot be loaded."), "openssl") . sprintf(_(" %s AUTH ignored."), 'Facebook'), E_USER_WARNING);
return $this->_tryNextUser();
}
$web = new HttpClient("www.facebook.com", 80);
if (DEBUG & _DEBUG_LOGIN) {
$web->setDebug(true);
}
// collect cookies from http://www.facebook.com/login.php
$web->persist_cookies = true;
$web->cookie_host = 'www.facebook.com';
$firstlogin = $web->get("/login.php");
if (!$firstlogin) {
if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) {
trigger_error(sprintf(_("Facebook connect failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING);
}
}
// Switch from http to https://login.facebook.com/login.php
$web->port = 443;
$web->host = 'login.facebook.com';
if (!($retval = $web->post("/login.php", array('user' => $userid, 'pass' => $password)))) {
if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE)) {
trigger_error(sprintf(_("Facebook login failed with %d %s"), $web->status, $web->errormsg), E_USER_WARNING);
}
}
$this->_authmethod = 'Facebook';
if (DEBUG & _DEBUG_LOGIN) {
trigger_error(get_class($this) . "::checkPass => {$retval}", E_USER_WARNING);
}
if ($retval) {
$this->_level = WIKIAUTH_USER;
} else {
$this->_level = WIKIAUTH_ANON;
}
return $this->_level;
}
示例12: preLogUser
function preLogUser($sessionId)
{
require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
$client = new HttpClient($this->getOption("REMOTE_SERVER"), $this->getOption("REMOTE_PORT"));
$client->setDebug(false);
if ($this->getOption("REMOTE_USER") != "") {
$client->setAuthorization($this->getOption("REMOTE_USER"), $this->getOption("REMOTE_PASSWORD"));
}
$client->setCookies(array($this->getOption("REMOTE_SESSION_NAME") ? $this->getOption("REMOTE_SESSION_NAME") : "PHPSESSID" => $sessionId));
$result = $client->get($this->getOption("REMOTE_URL"), array("session_id" => $sessionId));
if ($result) {
$user = $client->getContent();
if ($this->autoCreateUser()) {
AuthService::logUser($user, "", true);
} else {
// If not auto-create but the user exists, log him.
if ($this->userExists($user)) {
AuthService::logUser($user, "", true);
}
}
}
}
示例13: test
public function test()
{
$request = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => 'harry potter']];
$response = \HttpClient::get($request);
dd(\Parser::xml($response->content()));
}
示例14: installSlicer
function installSlicer($version, $installDir, $filename, $quiet, $disableTls, $cafile)
{
$installPath = (is_dir($installDir) ? rtrim($installDir, '/') . '/' : '') . $filename;
$installDir = realpath($installDir) ? realpath($installDir) : getcwd();
$file = $installDir . DIRECTORY_SEPARATOR . $filename;
if (is_readable($file)) {
@unlink($file);
}
if (FALSE === $disableTls && empty($cafile) && !HttpClient::getSystemCaRootBundlePath()) {
$errorHandler = new ErrorHandler();
set_error_handler([$errorHandler, 'handleError']);
$home = getenv('COMPOSER_HOME');
if (!$home) {
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if (!getenv('APPDATA')) {
throw new RuntimeException('The APPDATA or SLICER_HOME environment variable must be set for composer to install correctly');
}
$home = strtr(getenv('APPDATA'), '\\', '/') . '/Slicer';
} else {
if (!getenv('HOME')) {
throw new RuntimeException('The HOME or SLICER_HOME environment variable must be set for composer to install correctly');
}
$home = rtrim(getenv('HOME'), '/') . '/.slicer';
}
}
$target = $home . '/cacert.pem';
if (!is_dir($home)) {
@mkdir($home, 0777, TRUE);
}
$write = file_put_contents($target, HttpClient::getPackagedCaFile(), LOCK_EX);
@chmod($target, 0644);
restore_error_handler();
if (!$write) {
throw new RuntimeException('Unable to write bundled cacert.pem to: ' . $target);
}
$cafile = $target;
}
$httpClient = new HttpClient($disableTls, $cafile);
$retries = 3;
while ($retries--) {
if (!$quiet) {
out("Downloading...", 'info');
}
$uriScheme = FALSE === $disableTls ? 'https' : 'http';
$urlPath = (FALSE !== $version ? "/download/{$version}" : '') . '/slicer.phar';
$url = "{$uriScheme}://getslicer.com{$urlPath}";
$errorHandler = new ErrorHandler();
set_error_handler([$errorHandler, 'handleError']);
$fh = fopen($file, 'w');
if (!$fh) {
out('Could not create file ' . $file . ': ' . $errorHandler->message, 'error');
}
if (!fwrite($fh, $httpClient->get($url))) {
out('Download failed: ' . $errorHandler->message, 'error');
}
fclose($fh);
restore_error_handler();
if ($errorHandler->message) {
continue;
}
try {
// create a temp file ending in .phar since the Phar class only accepts that
if ('.phar' !== substr($file, -5)) {
copy($file, $file . '.tmp.phar');
$pharFile = $file . '.tmp.phar';
} else {
$pharFile = $file;
}
if (!ini_get('phar.readonly')) {
// test the phar validity
$phar = new Phar($pharFile);
// free the variable to unlock the file
unset($phar);
}
// clean up temp file if needed
if ($file !== $pharFile) {
unlink($pharFile);
}
break;
} catch (Exception $e) {
if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) {
throw $e;
}
// clean up temp file if needed
if ($file !== $pharFile) {
unlink($pharFile);
}
unlink($file);
if ($retries) {
if (!$quiet) {
out('The download is corrupt, retrying...', 'error');
}
} else {
out('The download is corrupt (' . $e->getMessage() . '), aborting.', 'error');
exit(1);
}
}
}
if ($errorHandler->message) {
out('The download failed repeatedly, aborting.', 'error');
//.........这里部分代码省略.........
示例15: onConnect
public function onConnect(IWebSocketConnection $user)
{
if ($user->getAdminKey() == self::$ADMIN_KEY) {
$this->say("[ECHO] Admin user connected");
return;
}
$h = $user->getHeaders();
$c = WebSocketFunctions::cookie_parse($h["Cookie"]);
$client = new HttpClient($this->host);
$client->cookies = $c;
$client->get("/{$this->path}/?get_action=ws_authenticate&key=" . self::$ADMIN_KEY);
$registry = $client->getContent();
//$this->say("[ECHO] Registry loaded".$registry);
$xml = new DOMDocument();
$xml->loadXML($registry);
$xPath = new DOMXPath($xml);
$err = $xPath->query("//message[@type='ERROR']");
if ($err->length) {
$this->say($err->item(0)->firstChild->nodeValue);
$user->disconnect();
} else {
$userRepositories = array();
$repos = $xPath->query("/tree/user/repositories/repo");
foreach ($repos as $repo) {
$repoId = $repo->attributes->getNamedItem("id")->nodeValue;
$userRepositories[] = $repoId;
}
$user->ajxpRepositories = $userRepositories;
$user->ajxpId = $xPath->query("/tree/user/@id")->item(0)->nodeValue;
if ($xPath->query("/tree/user/@groupPath")->length) {
$groupPath = $xPath->query("/tree/user/@groupPath")->item(0)->nodeValue;
if (!empty($groupPath)) {
$user->ajxpGroupPath = $groupPath;
}
}
}
$this->say("[ECHO] User '" . $user->ajxpId . "' connected with " . count($user->ajxpRepositories) . " registered repositories ");
}