PHP code example of powderblue / curl

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

    

powderblue / curl example snippets




$curl = new PowderBlue\Curl\Curl();

// When making `HEAD` and `GET` requests, parameters will be appended to the URL in the form of a query-string
$response = $curl->head($url, $requestParams);
$response = $curl->get($url, $requestParams);
// Otherwise, you can pass an associative array or a string to pop into the body of the request
$response = $curl->post($url, $requestBody);
$response = $curl->put($url, $requestBody);
$response = $curl->delete($url, $requestBody);

$response = $curl->request('<method-name>', $url, $requestBody);

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

// In this case, '?q=test' will be appended to the URL
$response = $curl->get('https://www.google.com/', ['q' => 'test']);

// The data will be encoded for you and the `Content-Type` header set to `multipart/form-data`
$response = $curl->post('test.com/posts', ['title' => 'Test', 'body' => 'This is a test']);

$response = $curl->get('https://www.google.com/');
echo $response->body;
print_r($response->headers);

<html>
<head>
<title>Google.com</title>
</head>
<body>
...
</body>
</html>

Array
(
    [Http-Version] => 1.0
    [Status-Code] => 200
    [Status] => 200 OK
    [Cache-Control] => private
    [Content-Type] => text/html; charset=ISO-8859-1
    [Date] => Wed, 07 May 2008 21:43:48 GMT
    [Server] => gws
    [Connection] => close
)

$curl->cookie_file = '<pathname>';

$curl->referer = '<url>';
$curl->user_agent = '<user-agent-string>';

$curl->headers['Host'] = 12.345.678.90;
$curl->headers['Custom-Header'] = 'foo';
$curl->headers['User-Agent'] = '<user-agent-string>';

$curl->follow_redirects = false;

$curl->options[CURLOPT_AUTOREFERER] = true;