本文整理汇总了PHP中Web::http方法的典型用法代码示例。如果您正苦于以下问题:PHP Web::http方法的具体用法?PHP Web::http怎么用?PHP Web::http使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web::http方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
Retrieve RSS/Atom feed and return as an array
@return mixed
@param $url string
@param $count int
@param $tags string
@public
**/
static function read($url, $count = 10, $tags = 'b;i;u;a')
{
$data = Web::http('GET ' . $url);
if (!$data) {
return FALSE;
}
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_ERR_FATAL);
if (!is_object($xml)) {
return FALSE;
}
$result = array();
if (isset($xml->channel)) {
$result['source'] = (string) $xml->channel->title;
foreach ($xml->channel->item as $item) {
$result['feed'][] = array('title' => (string) $item->title, 'link' => (string) $item->link, 'text' => strip_tags($item->description, '<' . implode('><', self::split($tags)) . '>'));
}
} elseif (isset($xml->entry)) {
$result['source'] = (string) $xml->author->name;
foreach ($xml->entry as $item) {
$result['feed'][] = array('title' => (string) $item->title, 'link' => (string) $item->link['href'], 'text' => strip_tags($item->summary, '<' . implode('><', self::split($tags)) . '>'));
}
} else {
return FALSE;
}
return array_slice($result, 0, $count);
}
示例2: callHttp
function callHttp($url, $query = '', $reqhdrs = array(), $follow = TRUE, $forward = FALSE, $contentType = 'application/x-www-form-urlencoded')
{
try {
return json_decode(Web::http($url, $query, $reqhdrs, $follow, $forward, $contentType));
} catch (Exception $e) {
return null;
}
}
示例3: followers
/**
Get information about user's followers via Twitter API
@return array
@param $userid string
@public
**/
static function followers($userid)
{
$response = json_decode(Web::http('GET http://api.twitter.com/1/statuses/followers/' . $userid . '.json'), TRUE);
if ($response['error']) {
trigger_error($response['error']);
return FALSE;
}
return $response;
}
示例4: feed
/**
Retrieve Atom/RSS feed using Google AJAX Feed API; If second
argument is TRUE, XML string returned; Otherwise, a PHP array
@return mixed
@param $url string
@param $isxml boolean
@public
**/
static function feed($url, $isxml = TRUE)
{
$result = json_decode(Web::http('GET http://ajax.googleapis.com/ajax/services/feed/load', http_build_query(array('v' => '1.0', 'q' => $url, 'num' => '-1', 'output' => $isxml ? 'xml' : 'json'))), TRUE);
if (is_null($result['responseData'])) {
trigger_error($result['responseDetails']);
return FALSE;
}
return $result['responseData'][$isxml ? 'xmlString' : 'feed'];
}
示例5: location
/**
Return geolocation data based on IP address, or FALSE on failure
@return mixed
@param $ip string
@public
**/
static function location($ip = NULL)
{
$data = unserialize(Web::http('GET http://www.geoplugin.net/php.gp?' . ($ip ? 'ip=' . $ip : '')));
if (!$data) {
return FALSE;
}
$result = array();
foreach ($data as $key => $val) {
$result[str_replace('geoplugin_', '', $key)] = $val;
}
return $result;
}
示例6: online
/**
Return online status of a Yahoo! ID
@return boolean
@param $id string
@public
**/
static function online($id)
{
$result = Web::http('GET http://opi.yahoo.com/online', http_build_query(array('u' => $id, 'm' => 'a', 't' => 1)));
return (bool) (int) $result;
}
示例7: location
/**
Return geolocation data based on IP address, or FALSE on failure
@return mixed
@param $ip string
@public
**/
static function location($ip = NULL)
{
$result = json_decode(Web::http('GET http://ipinfodb.com/ip_query.php?' . http_build_query(array('output' => 'json', 'ip' => $ip ?: NULL, 'timezone' => 'true'))), TRUE);
return $result ?: FALSE;
}
示例8: ham
/**
Report content as a false positive
@return boolean
@param $text string
@param $author string
@param $email string
@param $url string
@public
**/
static function ham($text, $author, $email, $url)
{
$response = Web::http('GET http://' . self::$key . '.rest.akismet.com/1.1/submit-ham', http_build_query(array('comment_content' => $text, 'comment_author' => $author, 'comment_author_email' => $email, 'comment_author_url' => $url, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'blog' => 'http://' . $_SERVER['SERVER_NAME'], 'permalink' => 'http://' . $_SERVER['SERVER_NAME'] . '/' . $_SERVER['REQUEST_URI'])));
return (bool) $response;
}
示例9: __set
/**
Bind value to OpenID request parameter
@param $key string
@param $val string
@public
**/
function __set($key, $val)
{
if ($key == 'identity') {
// Normalize
if (!preg_match('/https?:\\/\\//i', $val)) {
$val = 'http://' . $val;
}
$url = parse_url($val);
// Remove fragment; reconnect parts
$val = $url['scheme'] . '://' . (isset($url['user']) ? $url['user'] . (isset($url['pass']) ? ':' . $url['pass'] : '') . '@' : '') . strtolower($url['host']) . (isset($url['path']) ? $url['path'] : '/') . (isset($url['query']) ? '?' . $url['query'] : '');
$this->args['identity'] = $val;
// HTML-based discovery of OpenID provider
$text = Web::http('GET ' . $val);
$type = array_values(preg_grep('/Content-Type:/', self::$vars['HEADERS']));
if ($type && preg_match('/application\\/xrds\\+xml|text\\/xml/', $type[0]) && ($sxml = simplexml_load_string($text)) && ($xrds = json_decode(json_encode($sxml), TRUE)) && isset($xrds['XRD'])) {
// XRDS document
$svc = $xrds['XRD']['Service'];
if (isset($svc[0])) {
$svc = $svc[0];
}
if (preg_grep('/http:\\/\\/specs\\.openid\\.net\\/auth\\/2.0\\/' . '(?:server|signon)/', $svc['Type'])) {
$this->args['provider'] = $svc['URI'];
if (isset($svc['LocalID'])) {
$this->args['localidentity'] = $svc['LocalID'];
} elseif (isset($svc['CanonicalID'])) {
$this->args['localidentity'] = $svc['CanonicalID'];
}
}
$this->args['server'] = $svc['URI'];
if (isset($svc['Delegate'])) {
$this->args['delegate'] = $svc['Delegate'];
}
} else {
$len = strlen($text);
$ptr = 0;
// Parse document
while ($ptr < $len) {
if (preg_match('/^<link\\b((?:\\s+\\w+s*=\\s*(?:"(?:.+?)"|' . '\'(?:.+?)\'))*)\\s*\\/?>/is', substr($text, $ptr), $match)) {
if ($match[1]) {
// Process attributes
preg_match_all('/\\s+(rel|href)\\s*=\\s*' . '(?:"(.+?)"|\'(.+?)\')/s', $match[1], $attr, PREG_SET_ORDER);
$node = array();
foreach ($attr as $kv) {
$node[$kv[1]] = isset($kv[2]) ? $kv[2] : $kv[3];
}
if (isset($node['rel']) && preg_match('/openid2?\\.(\\w+)/', $node['rel'], $var) && isset($node['href'])) {
$this->args[$var[1]] = $node['href'];
}
}
$ptr += strlen($match[0]);
} else {
$ptr++;
}
}
}
// Get OpenID provider's endpoint URL
if (isset($this->args['provider'])) {
// OpenID 2.0
$this->args['ns'] = 'http://specs.openid.net/auth/2.0';
if (isset($this->args['localidentity'])) {
$this->args['identity'] = $this->args['localidentity'];
}
if (isset($this->args['trust_root'])) {
$this->args['realm'] = $this->args['trust_root'];
}
} elseif (isset($this->args['server'])) {
// OpenID 1.1
if (isset($this->args['delegate'])) {
$this->args['identity'] = $this->args['delegate'];
}
}
} else {
$this->args[$key] = self::resolve($val);
}
}
示例10: web
function web()
{
$this->set('title', 'Web Tools');
$this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text'));
$this->expect(extension_loaded('sockets'), 'Sockets extension available', 'Sockets extension is not active - unable to continue');
if (extension_loaded('sockets')) {
$text = 'Ñõw is the tîme~for all good mên. to cóme! to the aid 0f-thëir_côuntry';
$this->expect(Web::slug($text) == 'now-is-the-time-for-all-good-men-to-come-to-the-aid-0f-their_country', 'Framework generates correct URL-friendly version of string', 'Incorrect URL-friendly string conversion: ' . Web::slug($text));
$this->set('QUIET', TRUE);
$text = Web::http('GET http://' . $_SERVER['HTTP_HOST'] . '/minified/reset.css');
$this->expect($text == 'html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block;}body{line-height:1;}ol,ul{list-style:none;}blockquote,q{quotes:none;}blockquote:before,blockquote:after,q:before,q:after{content:\'\';content:none;}table{border-collapse:collapse;border-spacing:0;}', 'CSS minified ' . round(100 * (filesize('gui/reset.css') - strlen($text)) / filesize('gui/reset.css'), 1) . '%: ' . strlen($text) . ' bytes; ' . 'original size: ' . filesize('gui/reset.css') . ' bytes', 'CSS minification issue: ' . var_export($text, true));
$this->set('QUIET', FALSE);
$this->set('QUIET', TRUE);
$text = Web::http('GET http://' . $_SERVER['HTTP_HOST'] . '/minified/simple.css');
$this->expect($text == 'div *{text-align:center;}#content{border:1px #000 solid;text-shadow:#ccc -1px -1px 0px;}', 'CSS minified properly - necessary (and IE-problematic) spaces preserved', 'CSS minified incorrectly: ' . var_export($text, true));
$this->set('QUIET', FALSE);
$this->set('QUIET', TRUE);
$text = Web::http('GET http://' . $_SERVER['HTTP_HOST'] . '/minified/cookie.js');
$this->expect($text == 'function getCookie(c_name){if(document.cookie.length>0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));}}return""}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":"; expires="+exdate.toUTCString());}function checkCookie(){username=getCookie(\'username\');if(username!=null&&username!=""){alert(\'Welcome again \'+username+\'!\');}else{username=prompt(\'Please enter your name:\',"");if(username!=null&&username!=""){setCookie(\'username\',username,365);}}}', 'Javascript minified ' . round(100 * (filesize('gui/cookie.js') - strlen($text)) / filesize('gui/cookie.js'), 1) . '%: ' . strlen($text) . ' bytes; ' . 'original size: ' . filesize('gui/cookie.js') . ' bytes', 'Javascript minification issue: ' . var_export($text, true));
$this->set('QUIET', FALSE);
echo $this->render('basic/results.htm');
}
}
示例11: curl_exec
$response = curl_exec($ch);
echo $response;
//handle the message like following.
// list($headers, $content) = explode("\r\n\r\n", $response, 2);
// $schema_uri = F3::get('host_uri')."/sync_schema";
// // // Deserialize the data in the Ping message's body
// $content = Web::http('GET '.$schema_uri);
// $schema = AvroSchema::parse($content);
// $datum_reader = new AvroIODatumReader($schema);
// $read_io = new AvroStringIO($content);
// $decoder = new AvroIOBinaryDecoder($read_io);
// $message = $datum_reader->read($decoder);
// echo $message;
});
F3::route('POST /shipper_to_cart', function () {
$json_schema = Web::http('GET ' . F3::get('SESSION.ship_uri'));
$avro_schema = AvroSchema::parse($json_schema);
$datum_writer = new AvroIODatumWriter($avro_schema);
$write_io = new AvroStringIO();
$encoder = new AvroIOBinaryEncoder($write_io);
$ch = curl_init();
//get around php magic quotes if needed
//for json_decode to work
if (get_magic_quotes_gpc()) {
$d = stripslashes($_POST['json_message']);
} else {
$d = $_POST['json_message'];
}
$message = json_decode($d, true);
//$message = array("order" => array("orderID" => "123", "orderType" => "InHouse"));
$datum_writer->write($message, $encoder);