PHP code example of 10quality / php-curl

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

    

10quality / php-curl example snippets


// With global `curl_request()`
$response = curl_request('http://my-api.com');

// With global `get_curl_contents()`
// --- Which is an alias of `curl_request()`
$response = get_curl_contents('http://my-api.com');

// With class `Curl`
$response = Curl::request('http://my-api.com');

$response = curl_request($url, $method, $data, $headers, $options);

$response = curl_request(
    'http://my-api.com',
    'GET',
    [
        'action'    => 'get-countries',
        'format'    => 'xml',
    ]
);

$response = curl_request(
    'http://my-api.com',
    'POST',
    [
        'action'    => 'get-countries',
        'format'    => 'xml',
        'search'    => 'united',
        'limit'     => 5,
    ]
);

$response = curl_request(
    'http://my-api.com',
    'POST',
    [
        'query_string' => [
            'action'    => 'get-countries',
            'format'    => 'xml',
        ],
        'request_body' => [
            'search'    => 'united',
            'limit'     => 5,
        ],
    ]
);

$response = curl_request(
    'http://my-api.com',
    'GET',
    ['action' => 'get-countries'],
    [
        'Authorization: Bearer -token-',
        'Custom: Value',
    ]
);

$response = curl_request(
    'http://my-api.com',
    'GET',
    ['action' => 'get-countries'],
    [],
    [
        CURLOPT_TIMEOUT         => 60,
        CURLOPT_RETURNTRANSFER  => 0,
        CURLOPT_USERAGENT       => 'Custom/Agent 007',
    ]
);

$response = curl_request(
    'http://my-api.com',
    'XPOST',
    [],
    ['temperature' => 60, 'uptime' => 4564612131],
    [],// headers
    [],// options
    function($curl, $data) {
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'XPOST');
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
        return $curl;
    }
);
bash
composer