本文整理汇总了PHP中HttpClient::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::getUrl方法的具体用法?PHP HttpClient::getUrl怎么用?PHP HttpClient::getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::getUrl方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/** @return array of VcardAddress objects */
static function parse($data)
{
if (is_url($data)) {
$http = new HttpClient($data);
$data = $http->getBody();
//FIXME check http client return code for 404
if (strpos($data, 'BEGIN:VCARD') === false) {
throw new \Exception('VcardReader->parse FAIL: cant parse vcard from ' . $http->getUrl());
return false;
}
}
$res = array();
do {
$m1 = 'BEGIN:VCARD';
$m2 = 'END:VCARD';
$p1 = strpos($data, $m1);
$p2 = strpos($data, $m2);
if ($p1 === false || $p2 === false) {
break;
}
$part = substr($data, $p1, $p2 - $p1 + strlen($m2));
$res[] = self::parseVcard($part);
$data = substr($data, $p2 + strlen($m2));
} while ($data);
return $res;
}
示例2: handleWebhook
/**
* Handles the actual webhook, happens in two steps:
*
* - Retrieves the $webhook_id and $event_id
*
* - Uses the key and secret provided to fetch the event object and casts it to an array
*
* - Calls the callable function with the Event object
*/
private function handleWebhook()
{
$identifier = $this->field('identifier');
if ($identifier !== $this->identifier) {
return;
}
$event_id = $this->field('event_id');
$webhook_id = $this->field('webhook_id');
if (!$event_id || !$webhook_id) {
Log::info($this->patrol, 'Webhook ' . $this->identifier . ' has no event_id or webhook_id');
return;
}
$httpClient = new HttpClient($this->patrol, 'GET', 'webhooks/' . $webhook_id . '/events/' . $event_id);
$response = $httpClient->response();
if (!$response) {
Log::info($this->patrol, 'Retrieving webhook from ' . $httpClient->getUrl() . ' failed');
return;
}
$data = $this->field($response, 'data');
if (!$data) {
Log::info($this->patrol, 'Event has invalid format to be processed: ' . print_r($response, true));
}
$callable = $this->callback;
if (is_callable($callable)) {
$callable($data);
}
}
示例3: parse
function parse($data)
{
if (is_url($data)) {
$u = new HttpClient($data);
$data = $u->getBody();
//FIXME check http client return code for 404
if (strpos($data, '<feed ') === false) {
//dp('AtomReader->parse FAIL: cant parse feed from '.$u->getUrl() );
throw new \Exception('AtomReader->parse FAIL: cant parse feed from ' . $u->getUrl());
return false;
}
}
$this->reader = new \XMLReader();
$this->reader->xml($data);
while ($this->reader->read()) {
if ($this->reader->nodeType != \XMLReader::ELEMENT) {
continue;
}
switch ($this->reader->name) {
case 'feed':
if ($this->reader->getAttribute('xmlns') != 'http://www.w3.org/2005/Atom') {
throw new \Exception('Unknown atom xmlns: ' . $this->reader->getAttribute('xmlns'));
}
break;
case 'entry':
$this->parseEntry();
break;
case 'id':
break;
case 'title':
$this->reader->read();
$this->title = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8');
break;
case 'category':
// <category term="Nyheter" />
$this->category = $this->reader->getAttribute('term');
break;
case 'link':
break;
case 'generator':
break;
case 'updated':
break;
default:
//XXX: may include openSearch:itemsPerPage (twitter does for example)
// echo 'bad top entry '.$this->reader->name.ln();
break;
}
}
$this->reader->close();
return true;
}
示例4: query
private function query($method, $params)
{
$url = 'http://ws.audioscrobbler.com/2.0/?method=' . $method . '&api_key=' . $this->api_key;
$http = new HttpClient($url);
$http->setCacheTime('12h');
foreach ($params as $key => $val) {
$http->Url->setParam($key, $val);
}
echo "QUERYING " . $http->getUrl() . "\n";
$data = $http->getBody();
//d($data);
$x = simplexml_load_string($data);
/*
$attrs = $x->attributes();
if ($attrs['status'] == 'failed')
throw new \Exception ('last.fm api error: '.$x->error);
*/
return $x;
}
示例5: handleRequest
/**
* Adds authentication header to the request headers.
*
* @param HttpClient $request HTTP channel object.
*
* @return \HTTP_Request2
*/
public function handleRequest($request)
{
$signedKey = $this->_sharedKeyAuthentication->getAuthorizationHeader($request->getHeaders(), $request->getUrl(), $request->getUrl()->getQueryVariables(), $request->getMethod());
$request->setHeader(Resources::AUTHENTICATION, $signedKey);
return $request;
}
示例6: parse
function parse($data)
{
if (is_url($data)) {
$u = new HttpClient($data);
$u->setCacheTime(60 * 60);
//1h
$data = $u->getBody();
//FIXME check http client return code for 404
if (substr($data, 0, 5) != '<asx ') {
dp('input_asx->parse FAIL: cant parse playlist from ' . $u->getUrl());
return false;
}
}
$reader = new XMLReader();
if ($this->getDebug()) {
echo 'Parsing ASX: ' . $data . ln();
}
$reader->xml($data);
$item = new VideoResource();
while ($reader->read()) {
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'asx') {
$this->items[] = $item;
$item = new VideoResource();
}
if ($reader->nodeType != XMLReader::ELEMENT) {
continue;
}
switch ($reader->name) {
case 'asx':
if ($reader->getAttribute('version') != '3.0') {
die('XXX FIXME unsupported ASX version ' . $reader->getAttribute('version'));
}
break;
case 'entry':
while ($reader->read()) {
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'entry') {
break;
}
if ($reader->nodeType != XMLReader::ELEMENT) {
continue;
}
switch ($reader->name) {
case 'author':
break;
//<author>svt.se</author>
//<author>svt.se</author>
case 'copyright':
break;
//<copyright>Sveriges Television AB 2009</copyright>
//<copyright>Sveriges Television AB 2009</copyright>
case 'starttime':
break;
//<starttime value="00:00:00.00"/>
//<starttime value="00:00:00.00"/>
case 'ref':
//<ref href="mms://wm0.c90901.cdn.qbrick.com/90901/kluster/20091026/aekonomi920.wmv"/>
$item->setUrl($reader->getAttribute('href'));
break;
case 'duration':
//<duration value="00:03:39.00"/>
$item->setDuration($reader->getAttribute('value'));
break;
default:
echo "bad entry " . $reader->name . ln();
}
}
break;
default:
echo "unknown " . $reader->name . ln();
break;
}
}
$reader->close();
return true;
}
示例7: parse
function parse($data)
{
$base_url = '';
if (is_url($data)) {
//d($data);
$http = new HttpClient($data);
$http->setCacheTime(60 * 60);
//1h
$data = $http->getBody();
if (strpos($data, '#EXTM3U') === false) {
throw new \Exception('M3uReader->parse FAIL: cant parse feed from ' . $http->getUrl());
return false;
}
$base_url = dirname($http->getUrl());
}
$this->items = array();
$rows = explode("\n", $data);
$ent = new VideoResource();
//echo '<pre>';
foreach ($rows as $row) {
$row = trim($row);
$p = explode(':', $row, 2);
switch ($p[0]) {
case '#EXTM3U':
case '':
break;
/*
#EXT-X-VERSION:2
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
*/
/*
#EXT-X-VERSION:2
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
*/
case '#EXTINF':
$x = explode(',', $p[1], 2);
$ent->setDuration($x[0] != '-1' ? $x[0] : '');
$ent->setTitle($x[1]);
break;
// multiple quality streams for same media can exist
// multiple quality streams for same media can exist
case '#EXT-X-STREAM-INF':
// #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=294332
$x = explode(',', $p[1]);
foreach ($x as $kv) {
$x2 = explode('=', trim($kv), 2);
if ($x2[0] == 'PROGRAM-ID') {
$ent->track_id = $x2[1];
}
if ($x2[0] == 'BANDWIDTH') {
// XXX BITRATE???
$ent->bitrate = $x2[1];
}
}
break;
default:
if (substr($row, 0, 1) == '#') {
break;
}
if ($base_url && strpos($row, '://') === false) {
$row = $base_url . '/' . $row;
}
$ent->setUrl($row);
$this->items[] = $ent;
$ent = new VideoResource();
break;
}
}
}