PHP code example of phyrexia / http

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

    

phyrexia / http example snippets



Phyrexia\Http\Client as HttpClient;

//HTTP GET to www.google.fr
$response = HttpClient::get('http://www.google.fr');

//And now with a query string
$response = HttpClient::get('http://www.google.fr', 'a=1&b=c');

//Query string in array format
$response = HttpClient::get('http://www.google.fr', array('a' => 1, 'b' => 'c'));

//An HTTP POST with some data
$response = HttpClient::post('http://www.google.fr', array('user' => 'test', 'submit' => 1));

//You can also build an HttpClient object, and provide cURL options (::get, ::post and ::head support cURL options too)
$client = new HttpClient('http://www.google.fr', 'GET', array(CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 5));
$response = $client->send();

//The response is a Response object, if you just want the body, you can cast it as a string
$body = (string)HttpClient::get('http://www.google.fr');