public function post($url, $getParameters = array(), $postParameters, $isJson = false, $curlOptions = array())
 {
     $curl = new Curl();
     $curl->setUrl($url, $getParameters);
     $curl->setMethod(true);
     if ($isJson) {
         $postParameters = json_encode($postParameters);
         $curl->addOption('HTTP_HEADER', array('Content-Type: application/json'));
     }
     $curl->setPostParameters($postParameters);
     foreach ($curlOptions as $key => $value) {
         $curl->addOption($key, $value);
     }
     return $this->send($curl, $isJson);
 }
Example #2
0
 /**
  * @param string $url
  * @return Curl
  */
 public function create($url)
 {
     $curl = new Curl($url);
     foreach ($this->options as $option) {
         $curl->addOption($option[0], $option[1]);
     }
     return $curl;
 }
 private function postRequest($url, $fields)
 {
     $curl = new Curl();
     $curl->addHeader('Authorization: Bearer ', $fields['code']);
     $curl->addOption(CURLOPT_RETURNTRANSFER, true);
     $request = $curl->post($url, $fields);
     return $request;
 }
Example #4
0
 /**
  * cURL connection function. Returns data from Twitter and interfaces with
  * debug function.
  *
  * @param   bool    $login			Login to Twitter?
  * @param   bool    $post			Use POST instead of GET?
  * @param   array    $post_data		Array data for POST.
  * @return  string
  */
 private function connect($login = FALSE, $post = FALSE, $post_data = NULL)
 {
     // If credentials are required add them
     if ($login) {
         $login = $this->login;
     }
     // add default header info
     $this->headers[] = 'Expect:';
     $curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $this->url);
     // curl init
     $curl = new Curl($curl_options);
     // add curl options
     if (count($this->headers) > 0) {
         $curl->addOption(CURLOPT_HTTPHEADER, $this->headers);
     }
     if ($login) {
         $curl->addOption(CURLOPT_USERPWD, $this->login);
     }
     if ($post) {
         $curl->addOption(CURLOPT_POST, TRUE);
     }
     if (is_array($post_data)) {
         $curl->addOption(CURLOPT_POSTFIELDS, $post_data);
     }
     // retrieve data
     $data = $curl->execute($this->ignore_curl_error_numbers);
     // set curl http status
     $this->status = $curl->status();
     // set last call
     $this->last = $this->url;
     // clear settings
     $this->url = '';
     $this->headers = '';
     // debug output
     //	if (!IN_PRODUCTION AND Kohana::config('twitter.debug')) $this->debugo($data, $post_data);
     return $data;
 }
Example #5
0
/**
 * Simple Curl Library
 *
 * @author Federico Carrizo <*****@*****.**>
 * @url http://github.com/justfede/php-simple-curl
 */
namespace fedecarrizo\curl;

require "curl.php";
# SAMPLE GET REQUEST
$curl = new Curl();
$response = $curl->get("http://devfdxx.com/lab/tools/request.php?name=Federico");
echo $response;
# SAMPLE POST REQUEST
$curl = new Curl("http://devfdxx.com/lab/tools/request.php");
$response = $curl->post(['name' => 'Federico', 'last_name' => 'Carrizo']);
echo $response;
# ENABLE DEBUG
$curl->debug = 1;
# 1 will output errors
# FREQUENTLY OPTIONS
$curl->returnTransfer = true;
$curl->followLocation = true;
$curl->header = true;
$curl->url = 'http://example.com';
$curl->timeOut = 60;
$curl->connectionTimeOut = 60;
# CUSTOM OPTIONS
$curl->addOption(CURLOPT_USERAGENT, 'Googlebot/2.1');