Back to the module list

HTTP client

Get pages from site, manage the cookies between the pages, allow to follow the redirects. The cookies can be stored in an external file compatible with Netscape's cookies.txt. It allow to send forms fields or files.

Example 1 : Get a page

$httpclient = new \vendor\domframework\Httpclient ();
$httpclient->useragent ("Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0")
$content = $httpclient->getPage ("http://www.example.com");

Example 2 : Request a JSON page

$httpclient = new \vendor\domframework\Httpclient ();
$httpclient->headerAdd ("Content-Type", "application/json")
           ->url ("http://www.example.com")
           ->method ("POST");
$httpclient->connect ();
$page3 = $httpclient->getContent ();

Example 3 : Send form data

$page6 = $httpclient->method ("POST")
                    ->formData (['taskId' => 'aUniversMesComptes'])
                    ->url ($url)
                    ->connect ()
                    ->getContent ();