PHP code example of p3k / http

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

    

p3k / http example snippets


$http = new p3k\HTTP();
$headers = [
  'Accept: text/html, */*'
];
$response = $http->get('http://example.com/', $headers);

$http = new p3k\HTTP();
$headers = [
  'Accept: application/json',
  'Content-type: application/json'
];
$response = $http->post('http://example.com/', json_encode([
  'foo' => 'bar'
], $headers);

$http = new p3k\HTTP();
$headers = [
  'Accept: text/html, */*'
];
$response = $http->head('http://example.com/', $headers);

$http = new p3k\HTTP('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 p3k-http/0.1.0');
$http->get('http://example.com/');

$http = new p3k\HTTP();
$http->set_user_agent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 p3k-http/0.1.0');
$http->get('http://example.com/');

$http = new p3k\HTTP();
$http->set_transport(new p3k\HTTP\Stream());  // or your custom class here