本文整理汇总了PHP中HttpClient::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::getBody方法的具体用法?PHP HttpClient::getBody怎么用?PHP HttpClient::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parse
function parse($raw)
{
// TODO XmlReader should not handle HTTP protocol details
if (is_url($raw)) {
$url = $raw;
$h = new HttpClient($url);
// $h->setCacheTime('30m');
$raw = $h->getBody();
// d( $h->getResponseHeaders() );
if ($h->getStatus() == 404) {
// not found
return false;
}
if ($h->getStatus() == 302) {
$redir = $h->getResponseHeader('location');
// echo "REDIRECT: ".$redir."\n";
$h = new HttpClient($redir);
//XXX: reuse previous client?
$h->setCacheTime('30m');
$url = $redir;
$raw = $h->getBody();
}
// prepend XML header if nonexistent
if (strpos($raw, '<?xml ') === false) {
$raw = '<?xml version="1.0"?>' . $raw;
}
}
if (!$this->xml($raw)) {
if (isset($url)) {
throw new \Exception("Failed to parse XML from " . $url);
}
throw new \Exception("Failed to parse XML");
}
}
示例3: reverse
static function reverse($latitude, $longitude)
{
if (!$latitude || !$longitude) {
throw new \Exception('no coords set');
}
$temp = TempStore::getInstance();
$key = 'GeonamesClient//' . $latitude . '/' . $longitude;
$data = $temp->get($key);
if ($data) {
return unserialize($data);
}
$url = 'http://ws.geonames.org/timezone?lat=' . $latitude . '&lng=' . $longitude;
$http = new HttpClient($url);
$data = $http->getBody();
$xml = simplexml_load_string($data);
//d($xml);
$res = new GeoLookupResult();
$res->country_code = strval($xml->timezone->countryCode);
$res->country_name = strval($xml->timezone->countryName);
$res->timezone = strval($xml->timezone->timezoneId);
$res->sunrise = strval($xml->timezone->sunrise);
$res->sunset = strval($xml->timezone->sunset);
$temp->set($key, serialize($res), '1h');
return $res;
}
示例4: getRate
public static function getRate($from, $to)
{
$url = 'http://rate-exchange.appspot.com/currency?from=' . strtoupper($from) . '&to=' . strtoupper($to);
$http = new HttpClient($url);
$res = $http->getBody();
$json = json_decode($res);
return $json->rate;
}
示例5: shorten
static function shorten($input_url)
{
$url = 'http://is.gd/api.php?longurl=' . urlencode($input_url);
$http = new HttpClient($url);
$http->setCacheTime(86400);
//24 hours
$res = $http->getBody();
if (substr($res, 0, 4) == 'http') {
return trim($res);
}
throw new \Exception('Error: ' . $res);
}
示例6: 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;
}
示例7: shorten
static function shorten($url)
{
$url = 'http://tinyurl.com/api-create.php?url=' . urlencode($url);
$http = new HttpClient($url);
$http->setCacheTime(86400);
//24 hours
$res = $http->getBody();
if (substr($res, 0, 4) == 'http') {
return trim($res);
}
list($error_code, $error_message) = explode('|', $res);
throw new \Exception('Error: ' . $error_message . ' (' . $error_code . ')');
}
示例8: getRate
public static function getRate($from, $to)
{
$api_key = 'RFJGV-fViGD-R3FGa';
// api key for martin@ubique.se
$url = 'http://www.exchangerate-api.com/' . strtoupper($from) . '/' . strtoupper($to) . '?k=' . $api_key;
$http = new HttpClient($url);
$res = $http->getBody();
if ($res == '-2') {
throw new \Exception('unsupported currency:' . $from . ' or ' . $to);
}
if ($res == '-3') {
throw new \Exception('need api key, register your own at http://www.exchangerate-api.com/api-key');
}
if ($res < 0) {
throw new \Exception('error ' . $res);
}
return $res;
}
示例9: shorten
static function shorten($input_url)
{
/*
$login = 'bitlyapidemo';
$key = 'R_0da49e0a9118ff35f52f629d2d71bf07';
*/
$login = 'martinunicorn';
$key = 'R_f37747e06a18173096b714827c76b567';
$url = 'http://api.bit.ly/v3/shorten?format=json&login=' . $login . '&apiKey=' . $key . '&longUrl=' . urlencode($input_url);
$http = new HttpClient($url);
$http->setCacheTime(86400);
//24 hours
$res = Json::decode($http->getBody());
if ($res->status_code != 200) {
throw new \Exception('Error code ' . $res->status_code . ': ' . $res->status_txt);
}
return $res->data->url;
}
示例10: 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;
}
示例11: getByISBN
function getByISBN($isbn)
{
if (!Isbn::isValid($isbn)) {
throw new \Exception('invalid isbn');
}
$isbn = str_replace(' ', '', $isbn);
$isbn = str_replace('-', '', $isbn);
if ($this->use_cache) {
$temp = TempStore::getInstance();
$key = 'IsbnDbClient/isbn/' . $isbn;
$res = $temp->get($key);
if ($res) {
return unserialize($res);
}
}
$url = 'http://isbndb.com/api/books.xml' . '?access_key=' . $this->api_key . '&index1=isbn' . '&value1=' . $isbn;
$http = new HttpClient($url);
$data = $http->getBody();
$xml = simplexml_load_string($data);
$attrs = $xml->BookList;
if ($attrs['total_results'] == 0) {
return false;
}
$d = $xml->BookList->BookData;
$attrs = $d->attributes();
if (!$attrs) {
throw new \Exception('no attrs');
}
$book = new BookResource();
$book->title = strval($d->Title);
$book->authors = strval($d->AuthorsText);
$book->publisher = strval($d->PublisherText);
$book->isbn10 = strval($attrs['isbn']);
$book->isbn13 = strval($attrs['isbn13']);
if ($this->use_cache) {
$temp->set($key, serialize($book), '24h');
}
return $book;
}
示例12: getNasdaq
static function getNasdaq($symbol)
{
$format = 'n' . 's' . 'b2' . 'b3' . 'j' . 'k' . 'o' . 'p' . 'h' . 'g';
// Day's low
$url = 'http://download.finance.yahoo.com/d/quotes.csv' . '?s=' . urlencode($symbol) . '&f=' . $format;
$http = new HttpClient($url);
$data = $http->getBody();
$csv = CsvReader::parse($data);
if (count($csv) != 1) {
throw new \Exception('unhandled number of stock results: ' . count($csv));
}
$stock = new StockQuoteResult();
$stock->name = $csv[0][0];
$stock->symbol = $csv[0][1];
$stock->ask_realtime = $csv[0][2];
$stock->bid_realtime = $csv[0][3];
$stock->low_52w = $csv[0][4];
$stock->hi_52w = $csv[0][5];
$stock->open = $csv[0][6];
$stock->previous_close = $csv[0][7];
$stock->day_high = $csv[0][8];
$stock->day_low = $csv[0][9];
return $stock;
}
示例13: getAlbumDetails
/**
* @param $album_id spotify uri
*/
function getAlbumDetails($album_id)
{
if (!is_spotify_uri($album_id)) {
return false;
}
$url = 'http://ws.spotify.com/lookup/1/?uri=' . $album_id . '&extras=trackdetail';
$http = new HttpClient($url);
// $http->setCacheTime(60*60*24); //24 hours
$data = $http->getBody();
if ($http->getStatus() != 200) {
d('SpotifyMetadata->getAlbumDetails server error: ' . $http->getStatus());
d($http->getResponseHeaders());
return false;
}
return $this->parseAlbumDetails($data);
}
示例14: load
/**
* Loads input data from ASX playlists into VideoResource entries
*/
function load($data)
{
if (is_url($data)) {
$u = new HttpClient($data);
$data = $u->getBody();
}
if (strpos($data, '<asx ') !== false) {
$asx = new AsxReader();
$asx->parse($data);
$this->addItems($asx->getItems());
return true;
}
echo "Playlist->load error: unhandled feed: " . substr($data, 0, 200) . " ..." . ln();
return false;
}
示例15: connectURL
function connectURL($msg)
{
$httpclient = new HttpClient("true", HOST_IP);
$this->printLog("Start INImx_APPL");
$this->printLog("Start HTTP Connect:" . HOST_IP . $this->m_serviceurl);
if ($httpclient->HttpConnect()) {
$this->printLog("HTTP CONNECTION SUCCESS");
if ($httpclient->HttpRequest($this->m_serviceurl, $msg)) {
$this->printLog("RECV REQUEST:" . trim($httpclient->getBody()));
// ���� �� �Ľ�
parse_str(trim($httpclient->getBody()), $resultString);
//����
$this->m_tid = $resultString['P_TID'];
$this->m_resultCode = $resultString['P_STATUS'];
$this->m_resultMsg = $resultString['P_RMESG1'];
$this->m_payMethod = $resultString['P_TYPE'];
$this->m_mid = $resultString['P_MID'];
$this->m_moid = $resultString['P_OID'];
$this->m_resultprice = $resultString['P_AMT'];
$this->m_buyerName = $resultString['P_UNAME'];
$this->m_noti = $resultString['P_NOTI'];
$this->m_nextUrl = $resultString['P_NEXT_URL'];
$this->m_notiUrl = $resultString['P_NOTEURL'];
//�ſ�ī��
$this->m_pgAuthDate = substr($resultString['P_AUTH_DT'], '0', '8');
$this->m_pgAuthTime = substr($resultString['P_AUTH_DT'], '8', '6');
$this->m_authCode = $resultString['P_AUTH_NO'];
$this->m_cardQuota = $resultString['P_RMESG2'];
$this->m_cardCode = $resultString['P_FN_CD1'];
$this->m_cardIssuerCode = $resultString['P_CARD_ISSUER_CODE'];
$this->m_cardNumber = $resultString['P_CARD_NUM'];
$this->m_cardMember = $resultString['P_CARD_MEMBER_NUM'];
$this->m_cardpurchase = $resultString['P_CARD_PURCHASE_CODE'];
$this->m_prtc = $resultString['P_CARD_PRTC_CODE'];
//����
$this->m_codegw = $resultString['P_HPP_CORP'];
//�������
$this->m_vacct = $resultString['P_VACT_NUM'];
$this->m_dtinput = $resultString['P_VACT_DATE'];
$this->m_tminput = $resultString['P_VACT_TIME'];
$this->m_nmvacct = $resultString['P_VACT_NAME'];
$this->m_vcdbank = $resultString['P_VACT_BANK_CODE'];
} else {
$this->printLog("HTTP REQUEST FAIL:" . $httpclient->getErrorCode() . ":" . $httpclient->getErrorMsg());
// �� ���� ��û ����
$this->m_resultCode = "05";
$this->m_resultmsg = "HTTP REQUEST FAIL";
}
} else {
$this->printLog("HTTP CONNECTION FAIL:" . $httpclient->getErrorCode() . ":" . $httpclient->getErrorMsg());
// ���� ���� ����
$this->m_resultCode = "05";
$this->m_resultmsg = "HTTP CONNECTION FAIL";
}
$this->printLog("P_STATUS:" . $this->m_resultCode);
$this->printLog("P_RMESG1:" . $this->m_resultMsg);
$this->printLog("P_TYPE:" . $this->m_payMethod);
$this->printLog("P_TID:" . $this->m_tid);
$this->printLog("P_MID:" . $this->m_mid);
$this->printLog("P_OID:" . $this->m_moid);
$this->printLog("P_UNAME:" . $this->m_buyerName);
$this->printLog("P_AMT:" . $this->m_resultprice);
$this->printLog("P_AUTH_DT:" . $this->m_pgAuthDate);
$this->printLog("P_AUTH_TM:" . $this->m_pgAuthTime);
$this->printLog("P_AUTH_NO:" . $this->m_authCode);
$this->printLog("P_RMESG2:" . $this->m_cardQuota);
$this->printLog("P_FN_CD1:" . $this->m_cardCode);
$this->printLog("P_CARD_ISSUER_CODE:" . $this->m_cardIssuerCode);
$this->printLog("P_CARD_PURCHASE_CODE:" . $this->m_cardpurchase);
$this->printLog("P_CARD_PRTC_CODE:" . $this->m_prtc);
$this->printLog("P_VACT_NUM:" . $this->m_vacct);
$this->printLog("P_VACT_BANK_CODE:" . $this->m_vcdbank);
$this->printLog("P_VACT_DATE:" . $this->m_dtinput);
$this->printLog("P_VACT_TIME:" . $this->m_tminput);
$this->printLog("P_VACT_NAME:" . $this->m_nmvacct);
$this->printLog("P_NEXT_URL:" . $this->m_nextUrl);
$this->printLog("P_NOTEURL:" . $this->m_notiUrl);
$this->printLog("APPL Transaction End");
}