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

Hi!

Where can I get cURL library for CI3? I need it, because I want try to integrate SMSAPI.com
The best will be, when the library was the latest
Reply
#2

(08-07-2015, 09:31 AM)vertisan Wrote: Hi!

Where can I get cURL library for CI3? I need it, because I want try to integrate SMSAPI.com
The best will be, when the library was the latest


Simply try taking the PGP class library from : https://github.com/php-curl-class/php-curl-class 
and make it a  CI library  :-) 
Reply
#3

https://github.com/philsturgeon/codeigniter-curl

As noted on the page, it is no longer maintained, but I'm not aware of any specific issues in CI3. Links to alternatives are also included on the page, though you'll probably have to write a little code to adapt them for use in your application.
Reply
#4

I have adopted this library, with minor changes https://github.com/ivantcholakov/starter...s/Curl.php
Reply
#5

thanks for the links guys.
guzzle and requests cool...
Reply
#6

Guzzle 6 requires PHP 5.5. It is easy to be installed with Composer. But it needs to load some files immediately, so on PHP 5.3 it will cause PHP parsing error nevertheless you use this component or not.

Requests 1.6.1 requires PHP 5.2. It is lighter. For those who use the Curl library before and the Rest client library by Phil Sturgeon, Requests would be more familiar. It can be installed with Composer, I have chosen a manual installation, it is possible.
Reply
#7

I have installed everything within one project: https://github.com/ivantcholakov/codeign...erver-test
Reply
#8

I've just seen another interesting project: https://github.com/php-http/httplug "HTTPlug, the HTTP client abstraction for PHP."
If you are concerned not to be bound to a specific http-client implementation, have a look at it.
Reply
#9

I've been playing with guzzle lately.. it is so EASY to use, and seems like it will be around for quite some time. 
Example steps below to do a typical authenticate to a site  (from a library I'm working on)..
Bob
Ignition-Go


Steps: 
load library referencing guzzle, init the client, optionally set cookies, do HTTP/REST call(s), get response(s)
Code:
    $this->ci->load->library('guzzle'); /* from Ignition Go */

    $this->client = new GuzzleHttp\Client([
      'base_uri'=> $this->baseUrl /* base url you are using */,
    ' 'verify' => false /* for testing */
    ]);

        /* for session cookies */
    $this->cookieJar = new GuzzleHttp\Cookie\FileCookieJar($this->cookieFilePath,TRUE);

    $response = null;
        $parms = array('cookies'=> $this->cookieJar,
            'form_params' => array()  );
        $data['client_id'] = $this->client_id;
    $data['secret'] = $this->secret;
        $parms['form_params'] = $data;
       
        try {
          switch ($method) {
      case 'post':
        $response = $this->client->request( 'POST', $service, $parms);
            break;
      case 'get':
        $response = $this->client->request( 'GET', $service, $parms);
        break;
...

    echo $response->getStatusCode(); // 200
    echo $response->getReasonPhrase(); // OK
    echo $response->getProtocolVersion(); // 1.1
    echo $response->getBody();
    return json_decode($response->getBody(), true);
    }
catch (GuzzleHttp\Exception\BadResponseException $e) {
    $response = $e->getResponse();
    $responseBodyAsString = $response->getBody()->getContents();
    print_r($responseBodyAsString);
  }
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB