13.5. Zend_Http_Response
Prev | Chapter 13. Zend_Http | Next

## 13.5. Zend_Http_Response

### 13.5.1. Introduction

`Zend_Http_Response` provides easy access to the responses returned by Section 13.1, “Zend_Http_Client”. It provides an intuitive set of methods for working with the HTTP response data received from a request:

- `isError()`: Returns TRUE if an HTTP error code was received; FALSE otherwise.

- `isSuccessful()`: Returns TRUE if an HTTP success code was received; FALSE otherwise.

- `isRedirect()`: Returns TRUE if an HTTP redirect code was received; FALSE otherwise.

- `getStatus()`: Returns the HTTP status code.

- `getHeaders()`: Returns an array of HTTP response header strings.

- `getBody()`: Returns the HTTP response body as a string.

Example 13.23. Working with HTTP Response Data

    <?php
    require_once 'Zend/Http/Client.php';
    try {
        $http = new Zend_Http_Client('http://example.org');
        $response = $http->get();
        if ($response->isSuccessful()) {
            echo $response->getBody();
        } else {
            echo "<p>An error occurred</p>\n";
            echo "HTTP Status: " . $response->getStatus() . "\n";
            echo "HTTP Headers:\n";
            $responseHeaders = $response->getHeaders();
            foreach ($responseHeaders as $responseHeaderName => $responseHeaderValue) {
                echo "$responseHeaderName: $responseHeaderValue\n";
            }
        }
    } catch (Zend_Http_Client_Exception $e) {
        echo '<p>An error occurred (' .$e->getMessage(). ')</p>';
    }
    ?>

Prev | Up | Next
13.4. Zend_Http_Cookie and Zend_Http_CookieJar | Home | Chapter 14. Zend_Json