Welcome Guest, Not a member yet? Register   Sign In
cURL library - where can I get?
#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


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 visualsol - 11-30-2016, 12:06 AM
RE: cURL library - where can I get? - by cartalot - 11-30-2016, 12:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB