Welcome Guest, Not a member yet? Register   Sign In
cURL library - where can I get?
#10

(This post was last modified: 11-30-2016, 12:18 PM by cartalot.)

Learn how to use Curl. Its not that difficult. Once you have the basics down you can use the same template. You can put Curl code anywhere in codeigniter it does not have to be loaded like a library. I would also suggest learning how to use Guzzle - but learn Curl first because its in so many libraries and you don't want to be intimidated by it. Try and read the PHP Web Services book by Lorna Mitchell. Anyway here's a basic example of getting something thats been json encoded:

PHP Code:
 // set HTTP header for json 
$headers = array('Content-Type: application/json',);

// set the url for the service you are contacting 
// example has an id that is passed 
$url 'https://website.com/returnsomething/'.$id 

// Open connection
$ch curl_init();

// Set the url, number of GET vars, GET data
curl_setopt($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_POSTfalse);
curl_setopt($chCURLOPT_HTTPHEADER$headers);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue );

// this is controversial 
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);

// Execute request
$result curl_exec($ch);

// Close connection
curl_close($ch);

// get the result and parse to JSON
$something json_decode($result);

  if(isset($something)){ return $something ; }

  else { return FALSE ; } 
Reply


Messages In This Thread
cURL library - where can I get? - by vertisan - 08-07-2015, 09:31 AM
RE: cURL library - where can I get? - by eliorr - 08-07-2015, 09:59 AM
RE: cURL library - where can I get? - by mwhitney - 08-07-2015, 10:01 AM
RE: cURL library - where can I get? - by cartalot - 11-30-2016, 12:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB