PHP code example of s00d / guzzle-http-request

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

    

s00d / guzzle-http-request example snippets


'providers' => [
	// ...
	 s00d\GuzzleHttpRequest\GHRServiceProvider::class,
]

'aliases' => [
	// ...
	'GHR' => s00d\GuzzleHttpRequest\Facades\GHRFacade::class,
]

use GHR;
...

Config::set('ghr.cookie_file', "/cookie/text.txt");
$request = GHR::createRequest()->setProxy('tcp://127.0.0.1:8080')->setRedirects(5)->setHttpErrors(false)->setTimeout(500);
$request->addHeader('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
$response = $request->setUrl('https://localhost')->setType('POST')->send();

$crawler = $response->getCrawler();
try{
    $crawler->filter('.exit')->html();
    print_r(Carbon::now()->toTimeString().": Client auth\n");
} catch(\Exception $e) {
    print_r(Carbon::now()->toTimeString().": Client NOT auth\n");
}

$form = $crawler->selectButton('next')->form();

$form->setValues([
    'user' => $user,
]);

$response->sendForm($form);

var_dump($response->getContents());
var_dump($response->getJson());
...

$response = GHR::createRequest()
    ->setMultipleFlowCount(10) 
    ->setProxy('tcp://127.0.0.1:8080')
    ->removeDataParams()->addToQueue('/guzzle-test/get', 'GET', 0)
    ->setBody(['foo' => 'bar'], 'form_params')->addToQueue('/guzzle-test/post',    'POST',   1)
    ->setBody(['foo' => 'bar'], 'form_params')->addToQueue('/guzzle-test/put',     'PUT',    2)
    ->setBody(['foo' => 'bar'], 'form_params')->addToQueue('/guzzle-test/patch',   'PATCH',  3)
    ->setBody(['foo' => 'bar'], 'form_params')->addToQueue('/guzzle-test/delete'), 'DELETE', 4)
    ->multipleSend('form_params')->getMultiResp();

var_dump($response->responses()); // all responses
var_dump($response->errors());
var_dump($response->finished());


php artisan vendor:publish