minte9
LearnRemember




R Q

Requests

Requests is a HTTP library written in PHP, for human beings.
 
/**
 * Requests library
 * 
 * It is roughly based on the API from the excellent ...
 * Requests Python library.
 * 
 * Other HTTP libraries optimize for the library developer’s time.
 * Requests optimizes for your time.
 * 
 * composer require rmccue/requests
 */

require_once __DIR__ . '/vendor/autoload.php';

use WpOrg\Requests\Requests;

$url = 'http://httpbin.org/get';
$headers = ['Accept' => 'Application/json'];
$options = ['auth' => ['user', 'pass']];
$request = Requests::get($url, $headers, $options);

echo $request->status_code; // 200
echo $request->headers['content-type']; 
    // application/json; charset=utf-8

$body = json_decode($request->body);

echo $body->origin; // 188.26.232.235
echo $body->headers->Host; // httpbin.org

Questions