PHP Classes

File: tests/manually/HttpClientTestManually.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   tests/manually/HttpClientTestManually.php   Download  
File: tests/manually/HttpClientTestManually.php
Role: Unit test script
Content type: text/plain
Description: Unit test for manually testing HttpClientSocket
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of tests/manually/HttpClientTestManually.php
Date: 2 months ago
Size: 650 bytes
 

Contents

Class file image Download
<?php
set_include_path
(get_include_path() . PATH_SEPARATOR . '../../');

require_once
'vendor/autoload.php';

use
Generics\Client\HttpClient;
use
Generics\Socket\Url;

$http = new HttpClient(new Url('httpbin.org', 80));
$http->request('GET');

if (
$http->getResponseCode() == 200) {
   
$response = "";

    while (
$http->getPayload()->ready()) {
       
$response = $http->getPayload()->read(
           
$http->getPayload()->count()
        );
    }

    foreach (
$http->getHeaders() as $headerName => $headerValue) {
       
printf("%s: %s\n", $headerName, $headerValue);
    }
   
printf("Response: %s\n", $response);

   
$http->disconnect();
}