PHP code example of svyatov / curlwrapper

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

    

svyatov / curlwrapper example snippets


try {
    $curl = new CurlWrapper();
} catch (CurlWrapperException $e) {
    echo $e->getMessage();
}

$response = $curl->head($url, $params);
$response = $curl->get($url, $params);
$response = $curl->post($url, $params);
$response = $curl->put($url, $params);
$response = $curl->delete($url, $params);

$response = $curl->request($url, 'ANY_CUSTOM_REQUEST_TYPE', $params);

$response = $curl->get('google.com?q=test');

$response = $curl->get('google.com?q=test', array('some_variable' => 'some_value'));
// CurlWrapper will append '&some_variable=some_value' to the url

$response = $curl->post('test.com/posts', array('title' => 'Test', 'body' => 'This is a test'));

$response = $curl->rawPost($url, $jsonData);
$response = $curl->rawPut($url, 'raw random data');

$curl->addHeader('Content-Type', 'text/plain');
// or
$curl->addHeader('Content-Type', 'application/json');
// and then
$response = $curl->rawPost($url, $jsonData);

$info = $curl->getTransferInfo();

$httpCode = $curl->getTransferInfo('http_code');

$curl->setCookieFile('some_file_name.txt');

$curl->setReferer('http://google.com');
$curl->setUserAgent('some user agent string');
$curl->setTimeout(15); // seconds
$curl->setFollowRedirects(true); // to follow redirects

$curl->setAuthType();
$curl->setAuthCredentials('username', 'password');

$curl->addHeader('Host', '98.52.78.243');
$curl->addHeader('Some-Custom-Header', 'Some Custom Value');

$curl->addHeader(array('Host'=>'98.52.78.243', 'Some-Custom-Header'=>'Some Custom Value'));

$curl->addOption(CURLOPT_AUTOREFERER, true);