A collection of PHP classes used for making web requests, and parsing information related to the HTTP protocol.
This library contains classes which can be used to perform the following tasks:
- Make GET/POST requests to remote servers.
- Parse raw HTTP headers, and build raw HTTP headers.
- Parse raw HTTP requests.
- Provides a very small web server written in PHP for testing purposes.
The library may be installed using either git or Composer, but I strongly recommend using Composer so dependencies will be automatically installed. Add the web-tools dependency to your composer.json using the following code:
"require": {
"headzoo/web-tools" : "dev-master"
}
<?php
use Headzoo\Web\Tools\WebClient;
use Headzoo\Web\Tools\HttpMethods;
// Make a simple GET request.
$web = new WebClient();
$response = $web->get("http://headzoo.io");
// Make a simple POST request.
$web = new WebClient();
$response = $web->post("http://headzoo.io", ["arg1" => "value1"]);
// The response is an instance of WebResponse, which provides the response information.
echo $response->getCode();
echo $response->getBody();
print_r($response->getHeaders());
// Making a requests with more configuration.
$web = new WebClient(HttpMethods::GET);
$web
->addHeader("Content-Type", "application/json")
->setUserAgent("My-Web-Client")
->setBasicAuth("headzoo", "password");
$response = $web->request("http://headzoo.io");
This readme only briefly discussing some of the important classes in the library. See the class source code for more information.
Used to make any kind of HTTP request, including GET, POST, PUT, and DELETE.
Represents a server response from a HTTP request.
A small, not yet finished testing web server.
Represents an incoming web request.
Normalizes and builds raw HTTP headers.
Parses raw HTTP headers into an array of key/value pairs.
Parses a raw HTTP request into body, headers, etc.
Class of constants representing the supported request methods.
Contains various utility methods used through out the library.
- Major overhaul.
- Released code under MIT license.
- Add cookie management.
- Add certificate management.
This content is released under the MIT License. See the included LICENSE for more information.