1. Go to this page and download the library: Download rsong/phprequest 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/ */
$request = \EasyRequest\Client::request('https://google.com', 'GET', array(
'header' => array(
'User-Agent' => 'Firefox 45',
'Cookie' => 'cookie1=value1; cookie2=value2;',
'Example' => array(
'value 1',
'value 2'
)
),
));
// you also can use PSR7 as
$request = \EasyRequest\Client::request('https://google.com')
->withHeader('User-Agent', 'Firefox 45')
->withHeader('Example', array('value1', 'value 2'));
$jar = new \EasyRequest\Cookie\CookieJar;
// or
$jar = new \EasyRequest\Cookie\FileCookieJar($filePath);
// or
$jar = new \EasyRequest\Cookie\SessionCookieJar;
// add cookie from string of multiple cookies
$jar->fromString('cookie1=value1; cookie2=value2');
// add cookie with more information
$jar->add(Cookie::parse('cookie2=value2; path=/; domain=abc.com'));
// add cookie from \Psr\Http\Message\ResponseInterface
$jar->fromResponse($response);
// read more at \EasyRequest\Cookie\CookieJarInterface
$request = \EasyRequest\Client::request('https://google.com', 'GET', array(
'cookie_jar' => $jar
))->send();
var_dump($jar->toArray());
// or
var_dump($request->getOption('cookie_jar')->toArray());
var_dump((string) $jar);
$request = \EasyRequest\Client::request('http://domain.com', 'POST', array(
'bindto' => '123.123.123.123', // same as CURLOPT_INTERFACE option
));
$request = \EasyRequest\Client::request('http://domain.com', 'POST');
$response = $request->send();
// Returns \Psr\Http\Message\RequestInterface
var_dump($request->getRequest());
// Returns \Psr\Http\Message\ResponseInterface
// Or null if request is not sent or failure
var_dump($request->getResponse());
var_dump($response);
$request->getCurrentUri();
$response = $request->getResponse();
// you can use PSR7 here
$response->getHeaders();
$response->getHeader('Set-Cookie');
$response->getHeaderLine('Location');
$response->getProtocolVersion();
echo (string) $response->getBody();
var_dump($request->getRequests());
var_dump($request->getResponses());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.