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


PHP HTTP_Request类代码示例

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


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

示例1: getrss

 /**
  * getRSS
  * 
  * @access protected
  */
 protected function getrss($url)
 {
     require_once 'HTTP/Request.php';
     $req = new HTTP_Request($url, array('timeout' => 4, 'readTimeout' => array(4, 0)));
     $result = $req->sendRequest();
     if (PEAR::isError($result)) {
         $mes = htmlspecialchars($result->getMessage());
         return "<p class=\"warning\">RSSを読み込めません({$mes})。</p>";
     }
     $xml = @simplexml_load_string($req->getResponseBody());
     if ($xml === false) {
         return '<p class="warning">RSSを解釈できません。</p>';
     }
     $ret[] = '<ul class="plugin_rss">';
     foreach ($xml->item as $item) {
         /**
          * Namespace付きの子要素を取得
          * この場合、<dc:date>要素が対象
          */
         $dc = $item->children('http://purl.org/dc/elements/1.1/');
         $date = isset($dc->date) ? '&nbsp;(' . date('Y-m-d H:i', strtotime($dc->date)) . ')' : '';
         $_link = htmlspecialchars($item->link);
         $_title = htmlspecialchars(mb_convert_encoding($item->title, 'UTF-8', 'auto'));
         $line = '<li>';
         $line .= "<a href=\"{$_link}\">{$_title}</a>" . $date;
         $line .= '</li>';
         $ret[] = $line;
     }
     $ret[] = '</ul>';
     return join("\n", $ret);
 }
开发者ID:riaf,项目名称:kinowiki,代码行数:36,代码来源:rss.inc.php

示例2: getRequest

 /**
  * @brief HTTP request 객체 생성
  **/
 function getRequest($url)
 {
     $oReqeust = new HTTP_Request($url);
     $oReqeust->addHeader('Content-Type', 'application/xml');
     $oReqeust->setMethod('GET');
     return $oReqeust;
 }
开发者ID:hottaro,项目名称:xpressengine,代码行数:10,代码来源:lifepod.model.php

示例3: versionCheck

 /**
  * versionCheck - Get the most current version of nterchange and cache the result.
  *
  * @return 	array 	Information about the newest version of nterchange.
  **/
 function versionCheck()
 {
     require_once 'Cache/Lite.php';
     $options = array('cacheDir' => CACHE_DIR . '/ntercache/', 'lifeTime' => $this->check_version_interval);
     $cache = new Cache_Lite($options);
     $yaml = $cache->get($this->cache_name, $this->cache_group);
     if (empty($yaml)) {
         include_once 'HTTP/Request.php';
         $req = new HTTP_Request($this->check_version_url);
         if (!PEAR::isError($req->sendRequest())) {
             $yaml = $req->getResponseBody();
             $cached = $cache->save($yaml, $this->cache_name, $this->cache_group);
             if ($cached == true) {
                 NDebug::debug('Version check - data is from the web and is now cached.', N_DEBUGTYPE_INFO);
             } else {
                 NDebug::debug('Version check - data is from the web and is NOT cached.', N_DEBUGTYPE_INFO);
             }
         }
     } else {
         NDebug::debug('Version check - data is from the cache.', N_DEBUGTYPE_INFO);
     }
     require_once 'vendor/spyc.php';
     $newest_version_info = @Spyc::YAMLLoad($yaml);
     return $newest_version_info;
 }
开发者ID:nonfiction,项目名称:nterchange,代码行数:30,代码来源:version_check_controller.php

示例4: setInputFile

 /**
  * Sets the input xml file to be parsed
  *
  * @access  public
  * @param   string  $file  Filename(full path)
  * @return  mixed   True on success or error on failure
  */
 function setInputFile($file)
 {
     require_once PEAR_PATH . 'HTTP/Request.php';
     $httpRequest = new HTTP_Request($file, $this->_params);
     $httpRequest->setMethod(HTTP_REQUEST_METHOD_GET);
     $resRequest = $httpRequest->sendRequest();
     if (PEAR::isError($resRequest)) {
         return $resRequest;
     } elseif ($httpRequest->getResponseCode() != 200) {
         return $this->raiseError('HTTP response error', HTTP_REQUEST_ERROR_RESPONSE);
     }
     $data = trim($httpRequest->getResponseBody());
     if (version_compare(PHP_VERSION, '5.0.0', '<')) {
         if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $data, $matches)) {
             $srcenc = strtoupper($matches[1]);
             if (!in_array($srcenc, $this->_validEncodings)) {
                 if (function_exists('iconv')) {
                     $data = @iconv($srcenc, 'UTF-8', $data);
                 } elseif (function_exists('mb_list_encodings') && in_array($srcenc, array_map('strtoupper', mb_list_encodings()))) {
                     $data = @mb_convert_encoding($data, 'UTF-8', $srcenc);
                 }
             }
         }
     }
     $this->setInputString($data);
     return true;
 }
开发者ID:Dulciane,项目名称:jaws,代码行数:34,代码来源:XML_Feed.php

示例5: addRawImage

 protected function addRawImage($m)
 {
     $url = $m[3];
     if (isset($this->addedImage[$url])) {
         return $m[0];
     }
     if (isset(self::$imageCache[$url])) {
         $data =& self::$imageCache[$url];
     } else {
         if (ini_get_bool('allow_url_fopen')) {
             $data = file_get_contents($url);
         } else {
             $data = new HTTP_Request($url);
             $data->sendRequest();
             $data = $data->getResponseBody();
         }
         self::$imageCache[$url] =& $data;
     }
     switch (strtolower($m[4])) {
         case 'png':
             $mime = 'image/png';
             break;
         case 'gif':
             $mime = 'image/gif';
             break;
         default:
             $mime = 'image/jpeg';
     }
     $this->addHtmlImage($data, $mime, $url, false);
     $this->addedImage[$url] = true;
     return $m[0];
 }
开发者ID:nicolas-grekas,项目名称:Patchwork,代码行数:32,代码来源:agent.php

示例6: retrieveFile

 /**
  * Retrieves data from cache, if it's there.  If it is, but it's expired,
  * it performs a conditional GET to see if the data is updated.  If it
  * isn't, it down updates the modification time of the cache file and
  * returns the data.  If the cache is not there, or the remote file has been
  * modified, it is downloaded and cached.
  *
  * @param string URL of remote file to retrieve
  * @param int Length of time to cache file locally before asking the server
  *            if it changed.
  * @return string File contents
  */
 function retrieveFile($url, $cacheLength, $cacheDir)
 {
     $cacheID = md5($url);
     $cache = new Cache_Lite(array("cacheDir" => $cacheDir, "lifeTime" => $cacheLength));
     if ($data = $cache->get($cacheID)) {
         return $data;
     } else {
         // we need to perform a request, so include HTTP_Request
         include_once 'HTTP/Request.php';
         // HTTP_Request has moronic redirect "handling", turn that off (Alexey Borzov)
         $req = new HTTP_Request($url, array('allowRedirects' => false));
         // if $cache->get($cacheID) found the file, but it was expired,
         // $cache->_file will exist
         if (isset($cache->_file) && file_exists($cache->_file)) {
             $req->addHeader('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($cache->_file)) . " GMT");
         }
         $req->sendRequest();
         if (!($req->getResponseCode() == 304)) {
             // data is changed, so save it to cache
             $data = $req->getResponseBody();
             $cache->save($data, $cacheID);
             return $data;
         } else {
             // retrieve the data, since the first time we did this failed
             if ($data = $cache->get($cacheID, 'default', true)) {
                 return $data;
             }
         }
     }
     Services_ExchangeRates::raiseError("Unable to retrieve file {$url} (unknown reason)", SERVICES_EXCHANGERATES_ERROR_RETRIEVAL_FAILED);
     return false;
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:44,代码来源:Common.php

示例7: fetchUrlInfo

 /** Récupèration d'informations à propos de la ressource désignée par $this->href.
  *
  * La récupération des infos se fait en cascade :
  *   1. the encoding given in the charset parameter of the Content-Type HTTP header, or
  *   2. the encoding given in the encoding attribute of the XML declaration within the document, or
  *   3. utf-8.
  *
  * @see      http://diveintomark.org/archives/2004/02/13/xml-media-types
  * @todo     Terminer la recherche d'infos
  */
 function fetchUrlInfo()
 {
     // Envoi d'une requete vers l'URL
     require_once 'HTTP/Request.php';
     $r = new HTTP_Request($this->href);
     $r->sendRequest();
     // Récupération des informations contenues dans l'entête de la réponse.
     $url_info = $r->getResponseHeader();
     // --- Détermination du Content-Type et du Charset de la page --- //
     // 1. D'apres un entete http
     if (isset($url_info['content-type'])) {
         // eg. text/html; charset=utf8
         $pattern = '/^(\\w+\\/\\w+)(;?.\\w+=(.*))?/';
         if (preg_match($pattern, $url_info['content-type'], $matches)) {
             $content_type = isset($matches[1]) ? $matches[1] : null;
             $charset = isset($matches[3]) ? $matches[3] : null;
         }
     } else {
         $charset = 'utf8';
     }
     // Mise à jour des propriétés de l'objet en fonction des informations obtenues
     $this->type = $content_type;
     $this->charset = $charset;
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:blogmarks,代码行数:35,代码来源:Bm_Links.php

示例8: _fetch

 /**
  * Helper function to fetch HTTP-URLs
  *
  * @param string $url
  * @return string
  * @todo Error handling is missing
  */
 protected function _fetch($url)
 {
     require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
     $request = new HTTP_Request($url);
     $request->setMethod(HTTP_REQUEST_METHOD_GET);
     $request->sendRequest();
     return $request->getResponseBody();
 }
开发者ID:sqall01,项目名称:additional_plugins,代码行数:15,代码来源:abstract.php

示例9: shorten

 public function shorten($url)
 {
     $req = new HTTP_Request($this->apiurl . urlencode($url));
     if (!PEAR::isError($req->sendRequest())) {
         return $req->getResponseBody();
     }
     return "";
 }
开发者ID:vijo,项目名称:rss2twi.php,代码行数:8,代码来源:isgd.php

示例10: getRequest

 /**
  * @brief HTTP request 객체 생성
  **/
 function getRequest($url)
 {
     $oReqeust = new HTTP_Request($url);
     $oReqeust->addHeader('Content-Type', 'application/xml');
     $oReqeust->setMethod('GET');
     $oReqeust->setBasicAuth($this->getUserID(), $this->getPassword());
     return $oReqeust;
 }
开发者ID:hottaro,项目名称:xpressengine,代码行数:11,代码来源:springnote.model.php

示例11: shorten

 public function shorten($url, $text)
 {
     $req = new HTTP_Request($this->apiurl . '?url=' . urlencode($url) . "&text=" . urlencode($text) . "&maxchars=120");
     if (!PEAR::isError($req->sendRequest())) {
         return json_decode($req->getResponseBody(), true);
     }
     return "";
 }
开发者ID:vijo,项目名称:rss2twi.php,代码行数:8,代码来源:splanetphp.php

示例12: doSearch

 function doSearch($url)
 {
     $req = new HTTP_Request($url);
     $req->sendRequest();
     $contents = $req->getResponseBody();
     if (!xml_parse($this->_parser, $contents)) {
         die(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)));
     }
     xml_parser_free($this->_parser);
 }
开发者ID:sqall01,项目名称:additional_plugins,代码行数:10,代码来源:AmazonSearchEngine.class.php

示例13: SendTrackback

 /**
  * Send a trackback to a site
  *
  * @access  public
  * @param   string  $title     Title of the Site
  * @param   string  $excerpt   The Excerpt
  * @param   string  $permalink The Permalink to send
  * @param   array   $to        Where to send the trackback
  */
 function SendTrackback($title, $excerpt, $permalink, $to)
 {
     $title = urlencode(stripslashes($title));
     $excerpt = urlencode(stripslashes($excerpt));
     $blog_name = urlencode(stripslashes($this->gadget->registry->fetch('site_name', 'Settings')));
     $permalink = urlencode($permalink);
     require_once PEAR_PATH . 'HTTP/Request.php';
     $options = array();
     $timeout = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings');
     $options['timeout'] = $timeout;
     if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') {
         if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') {
             $options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings');
             $options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings');
         }
         $options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings');
         $options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings');
     }
     $httpRequest = new HTTP_Request('', $options);
     $httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
     foreach ($to as $url) {
         $httpRequest->setURL($url);
         $httpRequest->addPostData('title', $title);
         $httpRequest->addPostData('url', $permalink);
         $httpRequest->addPostData('blog_name', $blog_name);
         $httpRequest->addPostData('excerpt', $excerpt);
         $resRequest = $httpRequest->sendRequest();
         $httpRequest->clearPostData();
     }
 }
开发者ID:juniortux,项目名称:jaws,代码行数:39,代码来源:Trackbacks.php

示例14: get_url

 /**
  * serendipity_plugin_zooomr::getURL()
  * downloads the content from an URL and returns it as a string
  *
  * @author Stefan Lange-Hegermann
  * @since 02.08.2006
  * @param string $url URL to get
  * @return string downloaded Data from "$url"
  */
 function get_url($url)
 {
     require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
     $req = new HTTP_Request($url);
     if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
         $store = file_get_contents($url);
     } else {
         $store = $req->getResponseBody();
     }
     return $store;
 }
开发者ID:sqall01,项目名称:additional_plugins,代码行数:20,代码来源:serendipity_plugin_zooomr.php

示例15: getURL

 /**
  *
  */
 function getURL($url)
 {
     require_once PEAR_PATH . 'HTTP/Request.php';
     $httpRequest = new HTTP_Request($url);
     $httpRequest->setMethod(HTTP_REQUEST_METHOD_GET);
     $resRequest = $httpRequest->sendRequest();
     if (!PEAR::isError($resRequest) && $httpRequest->getResponseCode() == 200) {
         $data = $httpRequest->getResponseBody();
     } else {
         $data = @file_get_contents($url);
     }
     return $data;
 }
开发者ID:Dulciane,项目名称:jaws,代码行数:16,代码来源:AddressProtector.php


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