Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3.  
  4. class Rest
  5. {
  6.  
  7.     var $API = "";
  8.     protected $CI;
  9.  
  10.     function __construct()
  11.     {
  12.  
  13.         $this->CI = &get_instance();
  14.         $this->API = "https://192.168.1.36:8443/saber-cia-api/";
  15.     }
  16.  
  17.     public function send($method, $url, $header, $data)
  18.     {
  19.         //print_r($this->API.$url);
  20.         $ch = curl_init($this->API . $url);
  21.         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  22.         if ($data != null) {
  23.             $req = json_encode($data);
  24.             curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  25.         }
  26.  
  27.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28.         //start for https request
  29.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  30.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  31.         //end for https request
  32.         if ($header != null) {
  33.             curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  34.         }
  35.  
  36.         $result = curl_exec($ch);
  37.         $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  38.         curl_close($ch);
  39.  
  40.         //print_r($httpcode);
  41.         $response = json_decode($result, true);
  42.         return $response;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement