PHP Classes

File: tests/manually/HttpClientHeadTestManually.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   tests/manually/HttpClientHeadTestManually.php   Download  
File: tests/manually/HttpClientHeadTestManually.php
Role: Unit test script
Content type: text/plain
Description: Manually test the http client header retrieval
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of tests/manually/HttpClientHeadTestManually.php
Date: 7 months ago
Size: 625 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('HEAD');

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);
}