PHP code example of gesundberg / simplon_request

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

    

gesundberg / simplon_request example snippets


$req = new \Simplon\Request\Request();
    
$response = new \Simplon\Request\RequestResponse();


// set additional headers for request
$req->setRequestHeaders( [
	'User-Agent: Mozilla/5.0', 
	'Accept-Language: en-US,en'
] );	


// set request and response headers log file
// by default log file name -  headers_log.txt	
$req->setLog();							

$response = $req->get(URL, $data); 			// $data - array with variables for GET request


$location = $response->getHeader()->getLocation();	// if redirect

$type = $response->getHeader()->getContentType(); 	// return type of server response

if($response->getHeader()->isJson()) echo 'IsJson'; 	// check response type

$charset = $response->getHeader()->getCharset();	// return charset of response when Content-Type: text/html; charset=utf-8

$http_headers = $response->getHeader()->getHttpHeadersArray();
var_dump( $http_headers );				// show array of http headers of response

$html =  $response->getContent();
echo $html; 						// show server response without headers