1. Go to this page and download the library: Download ahmard/guzwrap 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/ */
use Guzwrap\Request;
$instance = Request::create();
//Do something...
use Guzwrap\Request;
Request::create()->get('http://localhost:8002')
->withCookie()
//or use cookie file
->withCookieFile('path/to/file')
//use cookie session
->withCookieSession('session_name')
//use array too
->withCookieArray([
'first_name' => 'Jane',
'other_names' => 'Doe'
], 'localhost')
//Use single cookie across requests
->withSharedCookie();
use Guzwrap\Request;
use Guzwrap\Wrapper\Redirect;
Request::get('http://localhost:8002')
->redirects(function(Redirect $redirect){
$redirect->max(5);
$redirect->strict();
$redirect->referer('http://goo.gl');
$redirect->protocols('http');
$redirect->trackRedirects();
$redirect->onRedirect(function(){
echo "Redirection detected!";
});
})->exec();
use Guzwrap\Request;
use Guzwrap\Wrapper\Header;
Request::get('http://localhost:8002')
->header(function(Header $header){
$header->add('hello', 'world');
$header->add('planet', 'earth');
})
->exec();
use Guzwrap\Request;
Request::get('https://google.com')
->query('q', 'Who is jane doe')
->exec();
use Guzwrap\Request;
use Guzwrap\Wrapper\Form;
Request::uri('http://localhost:8002')
->post(function(Form $form){
$form->field('first_name', 'Jane');
$form->field('last_name', 'Doe');
})
->exec();
//Post with multipart data
Request::uri('http://localhost:8002')
->post(function(Form $form){
$form->method('post');
$form->field('full_name', 'Jane Doe');
$form->file('avatar', 'C:\jane_doe.jpg');
})->exec();
use Guzwrap\Request;
use Guzwrap\Wrapper\Form;
use Guzwrap\Wrapper\File;
Request::form(function (Form $form){
$form->method('get'); //You can use any http method here
$form->action('localhost:8002');
$form->field('name', 'Guzwrap');
})->exec();
//Send file with custom information
Request::form(function(Form $form){
$form->method('post');
$form->action('http://localhost:8002');
$form->field('full_name', 'Jane Doe');
$form->file(function(File $file){
$file->field('avatar');
$file->path('C:\jane_doe.jpg');
$file->name('John_doe.gif');
});
})->exec();
use Guzwrap\Request;
use Guzwrap\Wrapper\Pool;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
each successful response
});
$pool->rejected(function (RequestException $reason, $index) {
// this is delivered each failed request
});
$pool->requests(function ($total) {
$uri = 'http://127.0.0.1:8002';
for ($i = 0; $i < $total; $i++) {
yield new \GuzzleHttp\Psr7\Request('GET', $uri);
}
});
});
$promise = $pool->promise();
$promise->then(function (ResponseInterface $response){
echo "{$response->getStatusCode()} @ {$response->getReasonPhrase()}\n";
});
$promise->wait();
use Guzwrap\Request;
use Guzwrap\UserAgent;
Request::userAgent(UserAgent::CHROME);
//Choose specific useragent index from array
Request::userAgent(UserAgent::CHROME, '1');
//Choose sub-useragent
Request::userAgent(UserAgent::CHROME, '9.1');
use Guzwrap\UserAgent;
$userAgents = UserAgent::init()->getAvailable();
use Guzwrap\UserAgent;
$randomUA = UserAgent::init()->getRandom();
use Guzwrap\UserAgent;
UserAgent::init()->addFile('/path/to/user-agents.json');
use Guzwrap\UserAgent;
use Guzwrap\Request;
$request = Request::userAgent(UserAgent::raw('Browser 1.0 (Windows NT 10.0; Win64; x64)'));
use Guzwrap\Request;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
Request::stack(function (HandlerStack $stack){
$stack->setHandler(new CurlHandler());
//Do something here
});
use Guzwrap\Request;
use Psr\Http\Message\RequestInterface;
/**
* An example of middleware that add header to requests
* @link https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html
*/
Request::middleware(function(){
return function (callable $handler){
return function (
RequestInterface $request,
array $options
) use ($handler){
$request = $request->withHeader('X-Guzwrap-Version', 'V2');
return $handler($request, $options);
};
};
});
use Guzwrap\Wrapper\Guzzle;
use Psr\Http\Message\ResponseInterface;
Client
{
return new Client();
}
public function boom(): ResponseInterface
{
echo "Executing request...\n";
return parent::exec();
}
}
$client = Client::create()
->get('localhost:8002')
->withCookie()
->boom();
bash
php -S localhost:8002 index.php
bash
php test.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.