Chapter 6. Zend_HttpClient

Table of Contents

6.1. Introduction
6.2. Basic GET Requests with Specified HTTP Headers
6.3. Requesting Multiple Domains
6.4. Changing the HTTP Timeout
6.5. Setting HTTP Headers Dynamically
6.6. Making HTTP POST, PUT, and DELETE Requests
6.7. Zend_HttpClient_Response
6.7.1. Introduction

6.1. Introduction

Zend_HttpClient provides an easy interface with which to perform HTTP requests. Zend_HttpClient is able to perform GET, POST, PUT and DELETE requests.

[Note] Note
Zend_HttpClient follows up to 5 HTTP redirections by default. To change this behavior, pass the maximum number of allowed redirections to the get() method.

Example 6.1. Performing a Basic GET Request

<?php
require_once 'Zend/HttpClient.php';
try {
    $http = new Zend_HttpClient('http://example.org');
    $response = $http->get();
    if ($response->isSuccessful()) {
        echo $response->getBody();
    } else {
        echo '<p>An error occurred</p>';
    }
} catch (Zend_HttpClient_Exception $e) {
    echo '<p>An error occurred (' .$e->getMessage(). ')</p>';
}
?>