PHP code example of sesser / scurl

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

    

sesser / scurl example snippets



	$scurl = Sesser\Scurl\Scurl::getInstance();
	$after_hash = $scurl->addListener(Sesser\Scurl\Scurl::EVENT_AFTER, function(Sesser\Scurl\Request $request, Sesser\Scurl\Response $response) {
		//-- Do some magic here... inspect the request headers, log the url and time it took, etc
	});


	$scurl = Sesser\Scurl\Scurl::getInstance();
	$scurl->removeListener(Sesser\Scurl\Scurl::EVENT_AFTER, $after_hash);

 function($errNo, $errMessage, Sesser\Scurl\Request $request); 
 php

	
 php

	$scurl = new Sesser\Scurl\Scurl;
	$response = $scurl->get('http://www.google.com');
	echo $response->body;
 php

	$scurl = new Sesser\Scurl\Scurl;
	$response = $scurl->put('http://api.awesomeapi.net/v1/upload/file.png', [], [
	  'data' => '/full/path/to/file.png'
	]);
 php

	$scurl = new Sesser\Scurl\Scurl;
	$response = $scurl->put('http://api.awesomeapi.net/v1/update', [ 'param' => 'value'], [
		'data' => '{"data": { "foo": "bar" }}',
		'headers' => ['Content-type' => 'application/json']
	]);
 php

$defaults = [
	'method' => Request::METHOD_GET,
	'auth' => [
		'user' => '',
		'pass' => ''
	],
	'data' => '',
	'parameters' => [],
	'cookie' => [],
	'headers' => [
		'Connection'	 =>  'keep-alive',
		'Keep-Alive'	 => 300,
		'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
		'Accept-Language' => 'en-us,en;q=0.5'			
	],
	'options' => [
		'user-agent' => 'Scurl/1.0; PHP/' . PHP_VERSION . ' (+http://github.com/sesser/scurl)',
		'timeout' => 10,
		'connect_timeout' => 2,
		'follow_location' => TRUE,
		'max_redirects' => 3
	],
];