當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。