PHP Classes

PHP HTTP Agent: Extensible HTTP client with a fluent interface

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 68 All time: 10,335 This week: 673Up
Version License PHP version Categories
httpagent 1.0.0MIT/X Consortium ...5HTTP, PHP 5
Description 

Author

This package provides an extensible HTTP client with a fluent interface.

It can define and send HTTP requests to remote servers using a fluent interface to setup several types of parameters like the request URL, method, headers, form input values, etc..

The package can also assign a callback function that is called to handle the server response data returned by the server.

Picture of Payam Naderi
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

 

Documentation

HttpAgent

$browser = new Browser('http://192.168.123.171/', [
    'request' => [
        'headers' => [
            'Accept' => 'application/json, text/javascript, /; q=0.01',
        ]
    ]
]);

$result = $browser->POST('/api/v1/auth/login'
    , [ 'form_data'
        => [
            'email'    => 'naderi.payam@gmail.com',
            'password' => '123456'
        ]
    ]
);

$result->expected(function(HttpResponse $httpResponse) use ($browser) {
    $jsonResult = $httpResponse->plg()->json();
    $authHeader = HeaderFactory::factory('Authorization', 'Bearer '.$jsonResult->token);
    $browser->inOptions()->getRequest()->getHeaders()->set(
        $authHeader
    );
});

$browser->GET('/api/v1/users/me', null, [
    'Accept' => 'application/json, text/javascript, /; q=0.01',
    'X-Requested-With' => 'XMLHttpRequest',
    'Referer' => 'http://localhost:8080/'
])->expected(function($response) {
    $response->flush(false);
});

$request =
        "GET /payam/ HTTP/1.1\r\n"
        ."Host: 95.211.189.240\r\n"
        ."User-Agent: AranRojan-PHP/5.5.9-1ubuntu4.11\r\n"
        ."Accept-Encoding: gzip\r\n"
        ."Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8\r\n"
        ."Cache-Control: no-cache"
    ;
    $browser = new Browser('http://95.211.189.240/', ['connection' => ['allow_decoding' => false]]);
    $res = $browser->request(new HttpRequest($request));

    echo ($res->getRawBody()->read());

  Files folder image Files (25)  
File Role Description
Files folder imageInterfaces (1 file, 1 directory)
Files folder imagePlatform (3 files, 1 directory)
Files folder imageTransporter (4 files, 1 directory)
Plain text file Browser.php Class Class source
Plain text file CommandRequestHttp.php Class Class source
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:68
This week:0
All time:10,335
This week:673Up