Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Curl
- *
- * @todo
- *
- * @version 1.0.0
- * @date last modified 11/07/2011
- */
- class Curl {
- public $curl_object;
- public function __construct($p_username = "", $p_password = "", $p_timeout = 15) {
- $this->curl_object = curl_init();
- curl_setopt($this->curl_object, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json"));
- curl_setopt($this->curl_object, CURLOPT_CONNECTTIMEOUT, $p_timeout);
- curl_setopt($this->curl_object, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($this->curl_object, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($this->curl_object, CURLOPT_USERAGENT, "curl 7.15.5 (x86_64-redhat-linux-gnu)");
- if(!empty($p_username) && !empty($p_password)) {
- curl_setopt($this->curl_object, CURLOPT_USERPWD, $p_username . ":" . $p_password);
- curl_setopt($this->curl_object, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- }
- }
- public function get_request($p_url) {
- curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
- return curl_exec($this->curl_object);
- }
- public function post_request($p_url, $p_post_data = "") {
- curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
- curl_setopt($this->curl_object, CURLOPT_POST, true);
- curl_setopt($this->curl_object, CURLOPT_POSTFIELDS, $p_post_data);
- return curl_exec($this->curl_object);
- }
- public function put_request($p_url) {
- curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
- curl_setopt($this->curl_object, CURLOPT_CUSTOMREQUEST, 'PUT');
- curl_setopt($this->curl_object, CURLOPT_POSTFIELDS, "");
- return curl_exec($this->curl_object);
- }
- public function delete_request($p_url) {
- curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
- curl_setopt($this->curl_object, CURLOPT_CUSTOMREQUEST, 'DELETE');
- return curl_exec($this->curl_object);
- }
- public function close() {
- curl_close($this->curl_object);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment