Overview

Abstract adapter to support various HTTP request backends.

Note that this class represents a standalone HTTP request, whereas Solar_Request represents the PHP request environment superglobals (including $_SERVER, $_ENV, $_POST, etc).

Here is an example request process:

<?php
$request = Solar::factory('Solar_Http_Request');

// fetch a response object for a GET request
$request->setUri('http://example.com');
$response = $request->fetch();

// fetch a response object for a POST request with some data
$request->setContent = array(...);
$request->setMethod('post');
$response = $request->fetch();

// fetch the response as raw text instead of a response object
$response = $request->fetchRaw();

This is a fluent class; you can chain the set*() and fetch() methods like so:

<?php
// fetch a response object for a POST request with some data
$request  = Solar::factory('Solar_Http_Request');
$response = $request->setUri('http://example.com')
                    ->setContent(array(...))
                    ->setMethod('post')
                    ->fetch();

To see the request message that will be sent, use __toString():

<?php
// fetch a response object for a POST request with some data
$request  = Solar::factory('Solar_Http_Request');
echo $request->setUri('http://example.com')
             ->setContent(array(...))
             ->setMethod('post')
             ->__toString();

Package

This class is part of the Solar_Http package.

Inheritance:

Configuration Keys

  • charset: The default character set.

  • content_type: The default content-type.

  • max_redirects: Follow no more than this many redirects.

  • proxy: Pass all requests through this proxy server.

  • timeout: Allowed connection timeout in seconds.

  • user_agent: The default User-Agent string.

  • version: The default HTTP version to use.

  • ssl_cafile: The local Certificate Authority file.

  • ssl_capath: If the CA file is not found, look in this directory for suitable CA files.

  • ssl_local_cert: The local certificate file.

  • ssl_passphrase: Passphrase to open the certificate file.

  • ssl_verify_peer: Whether or not to verify the peer SSL certificate.

  • auto_set_length: Whether or not to automatically set the Content-Length header.

Constants

None.

Public Properties

These are all the public properties in the Solar_Http_Request_Adapter class.

You can also view the list of all public, protected, and private properties.

$content

Content to send along with the request.

Public Methods

These are all the public methods in the Solar_Http_Request_Adapter class.

You can also view the list of all public, protected, and private methods.

__construct()

Constructor.

__destruct()

Default destructor; does nothing other than provide a safe fallback for calls to parent::__destruct().

__toString()

Returns this object as a string; effectively, the request message to be sent.

dump()

Convenience method for getting a dump the whole object, or one of its properties, or an external variable.

fetch()

Fetches the last Solar_Http_Response object from the specified URI.

fetchAll()

Fetches all Solar_Http_Response objects from the specified URI (this includes all intervening redirects).

fetchRaw()

Fetches from the specified URI and returns the response message as a string.

getContent()

Returns the body content.

getOptions()

Returns all options as an array.

locale()

Looks up class-specific locale strings based on a key.

setBasicAuth()

Sets "Basic" authorization credentials.

setCharset()

Sets the character set for the body content.

setContent()

Sets the body content; technically you can use the public $content property, but this allows method-chaining.

setContentType()

Sets the content-type for the body content.

setCookie()

Sets a cookie value in $this->_cookies to add to the request.

setCookies()

Sets multiple cookie values in $this->_cookies to add to the request.

setHeader()

Sets a header value in $this->_headers for sending at fetch() time.

setMaxRedirects()

When making the request, allow no more than this many redirects.

setMethod()

Sets the HTTP method for the request (GET, POST, etc).

setProxy()

Send all requests through this proxy server.

setReferer()

Sets the referer for the request.

setSslCafile()

Location of Certificate Authority file on local filesystem which should be used with the $_ssl_verify_peer option to authenticate the identity of the remote peer.

setSslCapath()

If $_ssl_cafile is not specified or if the certificate is not found there, this directory path is searched for a suitable certificate.

setSslLocalCert()

Path to local certificate file on filesystem.

setSslPassphrase()

Passphrase with which the $_ssl_local_cert file was encoded.

setSslVerifyPeer()

Require verification of SSL certificate used?

setTimeout()

Sets the request timeout in seconds.

setUri()

Sets the URI for the request.

setUserAgent()

Sets the User-Agent for the request.

setVersion()

Sets the HTTP protocol version for the request (1.0 or 1.1).



Local