PHP code example of adrii / curl-helper

1. Go to this page and download the library: Download adrii/curl-helper 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/ */

    

adrii / curl-helper example snippets


use Adrii\CurlHelper;



$curl = new CurlHelper();

$curl->setUrl('http://example.com/api/data');
$curl->setGetParams(['key' => 'value']);
$curl->execute();
$response = $curl->response();


$curl->setUrl('http://example.com/api/data');
$curl->setPostParams(['key' => 'value']);
$curl->execute();
$response = $curl->response();

$curl = new CurlHelper();
$curl->setUrl('https://example.com/api/data/1');
$curl->setPutParams(['key' => 'updatedValue']);
$curl->execute();
$response = $curl->response();

$curl = new CurlHelper();
$curl->setUrl('https://example.com/api/data/1');
$curl->execute();
$response = $curl->response();

$curl->setUrl('http://example.com/api/data');
$curl->setPostParams(['key' => 'value']);
$curl->execute();
$response = $curl->response();

$curl->setDebug();
$curl->execute();
$debugInfo = $curl->debug();

try {
    $curl->execute();
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

$url    = '{url}';
$basic  = '{basic}';

$curl = new CurlHelper();

$curl->setUrl($url);

$curl->setPostParams([
    'param' => '{param}',
    'type' => '{type}'
]);

$curl->setHeaders([
    "Authorization" => "Basic {$basic}"
], false); // Disable parse (dafault Enabled:true) 

$curl->setOptions([
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_2_0,
    CURLOPT_CONNECTTIMEOUT => 30,
]);

$curl->setMime("json");

$curl->setUtf8();

$curl->execute();

$response   = $curl->response();
$code       = $curl->http_code();

list($error, $msg) = $curl->parseCode();