Guest User

Untitled

a guest
Aug 24th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2. /**
  3. * Curl
  4. *
  5. * @todo
  6. *
  7. * @version 1.0.0
  8. * @date last modified 11/07/2011
  9. */
  10. class Curl {
  11. public $curl_object;
  12.  
  13. public function __construct($p_username = "", $p_password = "", $p_timeout = 15) {
  14. $this->curl_object = curl_init();
  15.  
  16. curl_setopt($this->curl_object, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json"));
  17. curl_setopt($this->curl_object, CURLOPT_CONNECTTIMEOUT, $p_timeout);
  18. curl_setopt($this->curl_object, CURLOPT_RETURNTRANSFER, 1);
  19. curl_setopt($this->curl_object, CURLOPT_SSL_VERIFYPEER, false);
  20. curl_setopt($this->curl_object, CURLOPT_USERAGENT, "curl 7.15.5 (x86_64-redhat-linux-gnu)");
  21.  
  22. if(!empty($p_username) && !empty($p_password)) {
  23. curl_setopt($this->curl_object, CURLOPT_USERPWD, $p_username . ":" . $p_password);
  24. curl_setopt($this->curl_object, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  25. }
  26. }
  27.  
  28. public function get_request($p_url) {
  29. curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
  30. return curl_exec($this->curl_object);
  31. }
  32.  
  33. public function post_request($p_url, $p_post_data = "") {
  34. curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
  35. curl_setopt($this->curl_object, CURLOPT_POST, true);
  36. curl_setopt($this->curl_object, CURLOPT_POSTFIELDS, $p_post_data);
  37. return curl_exec($this->curl_object);
  38. }
  39.  
  40. public function put_request($p_url) {
  41. curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
  42. curl_setopt($this->curl_object, CURLOPT_CUSTOMREQUEST, 'PUT');
  43. curl_setopt($this->curl_object, CURLOPT_POSTFIELDS, "");
  44. return curl_exec($this->curl_object);
  45. }
  46.  
  47. public function delete_request($p_url) {
  48. curl_setopt($this->curl_object, CURLOPT_URL, $p_url);
  49. curl_setopt($this->curl_object, CURLOPT_CUSTOMREQUEST, 'DELETE');
  50. return curl_exec($this->curl_object);
  51. }
  52.  
  53. public function close() {
  54. curl_close($this->curl_object);
  55. }
  56. }
  57. ?>
Add Comment
Please, Sign In to add comment