PHP code example of biohzrdmx / curly-php

1. Go to this page and download the library: Download biohzrdmx/curly-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

biohzrdmx / curly-php example snippets


use Curly\Curly;

$curly = Curly::newInstance()
  ->setMethod('GET')
  ->setURL('https://api.icndb.com/jokes/random')
  ->setParams([ 'limitTo' => 'nerdy' ])
  ->execute();

$response = $curly->getResponse();
if ($response && $response->getStatus() == 200) {
  $body = $response->getBody();
  if ($body->type == 'success') {
    echo $body->value->joke;
  }
} else {
  echo 'API error: ' . $curly->getError();
}

$cainfo = '/absolute/path/to/cacert.pem';
$curly = Curly::newInstance($cainfo);

$resource = fopen('/absolute/path/to/file.zip', 'wb');
if ($resource) {
  $curly = Curly::newInstance()
    ->setMethod('GET')
    ->setResource($resource)
    ->setURL('https://my-web-app.com/assets/file.zip')
    ->execute();
  $response = $curly->getResponse();
  fclose($resource);
}

use CURLFile;

$avatar = new CURLFile('/absolute/path/to/avatar.png');
$curly = Curly::newInstance()
  ->setMethod('POST')
  ->setURL('https://my-web-app.com/api/users/profile')
  ->setFields( ['email' => '[email protected]', 'avatar' => $avatar] )
  ->execute();