Skip to main content

CURL di CODEIGNITER

<?php class curl extends CI_Controller { public function __construct() { // created the construct so that the helpers, libraries, models can be loaded all through this controller parent::__construct(); $this->load->helper('url'); $this->load->library('xmlrpc'); $this->load->library('xmlrpcs'); } public function index() { //curl $mytoken = array('act'=>'GetToken', 'username'=>'*****', 'password'=>'*******'); $payload = json_encode($mytoken); $ch = curl_init('http://192.168.30.99:8082/ws/live2.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload)) ); $data = curl_exec($ch); if (curl_errno($ch)) { print "Error: " . curl_error($ch); } else { // Show me the result $transaction = json_decode($data, TRUE); curl_close($ch); var_dump($transaction['data']); } } }

Comments