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


PHP Curl::factory方法代码示例

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


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

示例1: pull

 /**
  * Quickly pulls data from a URI. This only works with GET requests but
  * can handle HTTP Basic Auth
  *
  * @param   string       uri  the url to pull from
  * @param   string       username  the username for the service [Optional]
  * @param   string       password  the password for the user [Optional]
  * @return  string
  * @throws  Kohana_User_Exception
  * @author  Sam Clark
  * @access  public
  * @static
  **/
 public static function pull($uri, $username = FALSE, $password = FALSE)
 {
     if (!valid::url($uri)) {
         throw new Kohana_User_Exception('Curl::pull()', 'The URL : ' . $uri . ' is not a valid resource');
     }
     // Initiate a curl session based on the URL supplied
     $curl = Curl::factory(array(CURLOPT_POST => FALSE), $uri);
     // If a username/password is supplied
     if ($username and $password) {
         // Add the HTTP Basic Auth headers
         $curl->setopt_array(array(CURLOPT_USERPWD => $username . ':' . $password));
     }
     // Launch the request and return the result
     return $curl->exec()->result();
 }
开发者ID:xig,项目名称:SocialFeed,代码行数:28,代码来源:Curl.php

示例2: post

 /**
  * Post
  * Execute an HTTP POST request, posting the past parameters
  * @param   string  $url    url to request
  * @param   array   $data   past data to post to $url
  * @param   array   $headers    additional headers to send in the request
  * @param   bool    $headers_only   flag to return only the headers
  * @param   array   $curl_options   additional curl options to instantiate curl with
  * @return  string  result 
  */
 public static function post($url, array $data = array(), array $headers = array(), $headers_only = FALSE, array $curl_options = array())
 {
     $ch = Curl::factory($curl_options);
     $ch->set_opt(CURLOPT_URL, $url)->set_opt(CURLOPT_NOBODY, $headers_only)->set_opt(CURLOPT_RETURNTRANSFER, TRUE)->set_opt(CURLOPT_POST, TRUE)->set_opt(CURLOPT_POSTFIELDS, $data);
     //Set any additional headers
     if (!empty($headers)) {
         $ch->set_opt(CURLOPT_HTTPHEADER, $headers);
     }
     return $ch->execute();
 }
开发者ID:AlexKupreev,项目名称:kohana-curl,代码行数:20,代码来源:curl.php

示例3: reload_curl

 /**
  * Reloads the cURL library after execution
  *
  * @return  void
  * @author  Sam Clark
  * @access  public
  */
 public function reload_curl()
 {
     // If there is no cURL library or cURL has executed
     if ($this->curl === NULL or $this->curl->executed) {
         $this->curl = Curl::factory(array(CURLOPT_POST => FALSE));
     }
     return;
 }
开发者ID:nocash,项目名称:kohana-yql,代码行数:15,代码来源:YQL.php

示例4: get

 /**
  * Quickly gets data from a URI. This only works with GET requests but
  * can handle HTTP Basic Auth
  *
  * @param   string       uri  the url to pull from
  * @param   string       username  the username for the service [Optional]
  * @param   string       password  the password for the user [Optional]
  * @return  string
  * @return  void
  * @throws  Kohana_User_Exception
  * @access  public
  * @static
  **/
 public static function get($url, $username = FALSE, $password = FALSE)
 {
     if (!valid::url($url)) {
         throw new Kohana_User_Exception(__CLASS__ . '.' . __METHOD__ . '()', 'The URL : ' . $url . ' is not a valid resource');
     }
     // Initiate a curl session based on the URL supplied
     $curl = Curl::factory(array(CURLOPT_POST => FALSE), $url);
     // If a username/password is supplied
     if ($username and $password) {
         // Add the HTTP Basic Auth headers
         $curl->setopt_array(array(CURLOPT_USERPWD => $username . ':' . $password));
     }
     // Run the curl request
     $curl->exec();
     // If there was an error, return null
     if ($curl->error()) {
         return;
     } else {
         return $curl->result();
     }
 }
开发者ID:nocash,项目名称:kohana-curl,代码行数:34,代码来源:Curl.php


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