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


PHP HTTP_Request::sendRequest方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: exportarDados

 /**
  * Método que encapsula a chamada do WEB SERVICE que traduz um arquivo .HTML em outras extensões.
  * Utilizado para exportar dados para arquivos a desejo do usuário.
  * 
  * @param texto $arquivoFetch nome do arquivo a ser utilizado para exportação, desde a pasta 'html'.
  * @param texto $extensaoDestino mine type para arquivo exportado.
  * @param texto $nomeArquivo nome a ser exibido no download do arquivo.
  */
 function exportarDados($arquivoFetch, $nomeArquivo = "Relatório.pdf", $extensaoDestino = "application/pdf", $fazerDownload = true)
 {
     $codigoHtml = $this->smarty->fetch($arquivoFetch);
     $codigoHtml = str_replace("html/css/", URL_COMPLETA . "html/css/", $codigoHtml);
     $codigoHtml = str_replace("html/img/", URL_COMPLETA . "html/img/", $codigoHtml);
     $request = new HTTP_Request(WEBSERVICE_BROFFICE_URL);
     $request->setMethod("POST");
     $request->addHeader("Content-Type", "text/html");
     $request->addHeader("Accept", $extensaoDestino);
     $request->setBody($codigoHtml);
     $request->sendRequest();
     $status = $request->getResponseCode();
     //echo $request->getResponseBody(); die;
     if ($status != 200) {
         echo "Ocorreu um erro na conversão. Favor entrar em contato com o administrador.";
         die;
     }
     if ($fazerDownload) {
         header("Content-Type: " . $extensaoDestino . "\n");
         header("Content-Disposition: attachment; filename=" . $nomeArquivo);
         echo $request->getResponseBody();
         die;
     }
     return $request->getResponseBody();
 }
开发者ID:ViniciusFelix,项目名称:ProjetoPadrao,代码行数:33,代码来源:negocio.php

示例6: save

 function save($data)
 {
     if (!$data['GA_optin']) {
         trigger_error('did not opt to join');
         return true;
     }
     $options = $this->getOptions();
     $request = new HTTP_Request($options['hostname'] . '/offsite-join.tcl');
     $request->setMethod(HTTP_REQUEST_METHOD_POST);
     $request->addPostData('domain', $options['domain']);
     if ($options['source']) {
         $request->addPostData('source', $options['source']);
     }
     if ($options['update']) {
         $request->addPostData('update', $options['update']);
     }
     foreach ($this->translate($data) as $name => $value) {
         $request->addPostData($name, $value);
     }
     if (!PEAR::isError($request->sendRequest())) {
         $message = trim($request->getResponseBody());
         if ('OK' == $message) {
             return true;
         } else {
             $this->ERROR = $message;
             trigger_error($message);
             return false;
         }
     }
 }
开发者ID:radicaldesigns,项目名称:amp,代码行数:30,代码来源:Save.inc.php

示例7: fetchData

 function fetchData($username, $password)
 {
     switch ($this->options['cryptType']) {
         case 'blowfish':
             include_once 'Crypt/Blowfish.php';
             $bf = new Crypt_Blowfish($this->options['cryptKey']);
             $password = $bf->encrypt($password);
             $password = base64_encode($password);
             break;
         default:
             if (function_exists($this->options['cryptType'])) {
                 $password = $this->options['cryptType']($password);
             }
             break;
     }
     $req = new HTTP_Request();
     $req->setURL($this->options['URL']);
     $req->setMethod(HTTP_REQUEST_METHOD_GET);
     $req->addQueryString($this->options['usernameKey'], $username);
     $req->addQueryString($this->options['passwordKey'], $password);
     if (!PEAR::isError($req->sendRequest())) {
         $response = $req->getResponseBody();
     } else {
         return false;
     }
     $unserializer = new XML_Unserializer();
     if ($unserializer->unserialize($response)) {
         $this->result_value = $unserializer->getUnserializedData();
         if ($this->result_value[$this->options['resultKey']] == $this->options['correctValue']) {
             return true;
         }
     }
     return false;
 }
开发者ID:KimuraYoichi,项目名称:PukiWiki,代码行数:34,代码来源:REST_XML.php

示例8: SendRequest

 /**
  * @param bool $saveBody
  * @return PEAR_Error|mixed|void
  */
 function SendRequest($saveBody = true)
 {
     // Unless the user has expressly set the proxy setting
     $defaultProxy = null;
     if ($this->useProxy == null) {
         // Is this localhost traffic?
         if (strstr($this->getUrl(), "localhost") !== false) {
             // Yes, don't proxy
             $defaultProxy = false;
         }
     }
     // Setup the proxy if needed
     //   useProxy + defaultProxy both need to be null or true
     if ($this->useProxy !== false && $defaultProxy !== false) {
         global $configArray;
         // Proxy server settings
         if (isset($configArray['Proxy']['host'])) {
             if (isset($configArray['Proxy']['port'])) {
                 $this->setProxy($configArray['Proxy']['host'], $configArray['Proxy']['port']);
             } else {
                 $this->setProxy($configArray['Proxy']['host']);
             }
         }
     }
     // Send the request via the parent class
     parent::sendRequest($saveBody);
 }
开发者ID:bryandease,项目名称:VuFind-Plus,代码行数:31,代码来源:Proxy_Request.php

示例9: 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

示例10: 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

示例11: 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

示例12: prepare

 /**
  *  preprocess Index action.
  *
  *  @access    public
  *  @return    string  Forward name (null if no errors.)
  */
 function prepare()
 {
     if ($this->af->validate() == 0) {
         /// download file
         $url = sprintf('%s/repository.sphp', rtrim($this->af->get('repository_url'), '/'));
         $cache_file = $this->backend->ctl->repositoryURL2CacheFile($url);
         $repo_data = unserialize(file_get_contents($cache_file));
         list($package, $version) = explode('@', $this->af->get('target_package'));
         $urls = array();
         foreach ($repo_data as $package_name => $package_data) {
             if ($package_name == $package) {
                 foreach ($package_data as $_pdata) {
                     if ($_pdata['version'] == $version) {
                         $urls = $_pdata['urls'];
                         $filesize = $_pdata['size'];
                     }
                 }
             }
         }
         require_once 'HTTP/Request.php';
         $req = new HTTP_Request();
         $req->setMethod(HTTP_REQUEST_METHOD_HEAD);
         $command = 'no command';
         foreach ($urls as $_url_data) {
             $_url = $_url_data['url'];
             $req->setURL($_url);
             $req->sendRequest();
             if ($req->getResponseCode() == "302") {
                 $headers = $req->getResponseHeader();
                 $req->setURL($headers['location']);
             }
             $req->sendRequest();
             if ($req->getResponseCode() == '200') {
                 $data_file = $this->backend->ctl->package2dataFile($package, $version);
                 if ($this->fetchTgzFile($data_file, $req->getUrl())) {
                     if (filesize($data_file) == $filesize || !$filesize) {
                         chmod($data_file, 0666);
                         return null;
                     }
                 }
             }
         }
         $this->ae->add('wget failed', _('file download failed.') . '[debug]' . sprintf('SIZE:[datafile,%d => repos,%d]', filesize($data_file), $filesize));
     }
     return 'json_error_reload';
 }
开发者ID:hiro1173,项目名称:legacy,代码行数:52,代码来源:Downloadpackage.php

示例13: 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

示例14: _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

示例15: 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


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