HTTP_Client
[ class tree: HTTP_Client ] [ index: HTTP_Client ] [ all elements ]

Class: HTTP_Client

Source Location: /HTTP_Client-1.2.1/Client.php

Class Overview


A simple HTTP client class.


Author(s):

Version:

  • Release: 1.2.1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 100]
A simple HTTP client class.

The class wraps around HTTP_Request providing a higher-level API for performing multiple HTTP requests

Note that the class implements all the methods defined by the Iterator interface for going over the received responses. Being PHP4-compatible it is not declared with 'implements Iterator', though. Therefore if you are running PHP5 and want to use HTTP_Client in 'foreach' context you should do the following:

  1.  class PHP5_HTTP_Client extends HTTP_Client implements Iterator {}
  2.  
  3.  $client = new PHP5_HTTP_Client();
  4.  
  5.  // ... perform requests ...
  6.  
  7.  foreach ($client as $url => $response{
  8.      // do something
  9.  }

If you are running PHP4 you'll have to call the methods manually:

  1.  for ($client->rewind()$client->valid()$client->next()) {
  2.      $url $client->key();
  3.      $response $client->current();
  4.      // do something
  5.  }

  • Author: Alexey Borzov <avb@php.net>
  • Version: Release: 1.2.1


[ Top ]


Method Detail

HTTP_Client (Constructor)   [line 174]

HTTP_Client HTTP_Client( [array $defaultRequestParams = null], [array $defaultHeaders = null], [HTTP_Client_CookieManager $cookieManager = null])

Constructor
  • Access: public

Parameters:

array   $defaultRequestParams   —  Parameters to pass to HTTP_Request's constructor
array   $defaultHeaders   —  Default headers to send on every request
HTTP_Client_CookieManager   $cookieManager   —  Cookie manager object to use

[ Top ]

attach   [line 533]

boolean attach( HTTP_Request_Listener &$listener, [boolean $propagate = false])

Adds a Listener to the list of listeners that are notified of the object's events

Events sent by HTTP_Client objects:

  • 'request': sent on HTTP request that is not a redirect
  • 'httpSuccess': sent when we receive a successfull 2xx response
  • 'httpRedirect': sent when we receive a redirection response
  • 'httpError': sent on 4xx, 5xx response

  • Return: whether the listener was successfully attached
  • Access: public

Parameters:

HTTP_Request_Listener   &$listener   —  Listener to attach
boolean   $propagate   —  Whether the listener should be attached to the created HTTP_Request objects

[ Top ]

current   [line 666]

array current( )

Returns the current element (HTTP response)
  • Access: public

[ Top ]

currentResponse   [line 477]

array &currentResponse( )

Returns the most recent HTTP response

To access previous responses use iteration methods

  • Access: public

[ Top ]

delete   [line 347]

integer delete( string $url, [array $headers = array()])

Sends a 'DELETE' HTTP request
  • Return: HTTP response code
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $url   —  URL
array   $headers   —  Extra headers to send

[ Top ]

detach   [line 551]

boolean detach( HTTP_Request_Listener &$listener)

Removes a Listener from the list of listeners
  • Return: Whether the listener was successfully detached
  • Access: public

Parameters:

HTTP_Request_Listener   &$listener   —  Listener to detach

[ Top ]

enableHistory   [line 212]

void enableHistory( bool $enable)

Sets whether to keep all the responses or just the most recent one
  • Access: public

Parameters:

bool   $enable   —  Whether to enable history

[ Top ]

get   [line 273]

integer get( string $url, [mixed $data = null], [boolean $preEncoded = false], [array $headers = array()])

Sends a 'GET' HTTP request
  • Return: HTTP response code
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $url   —  URL
mixed   $data   —  additional data to send
boolean   $preEncoded   —  Whether the data is already urlencoded
array   $headers   —  Extra headers to send

[ Top ]

getCookieManager   [line 617]

HTTP_Client_CookieManager getCookieManager( )

Returns the cookie manager object (e.g. for storing it somewhere)
  • Access: public

[ Top ]

head   [line 255]

integer head( string $url, [array $headers = array()])

Sends a 'HEAD' HTTP request
  • Return: HTTP response code
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $url   —  URL
array   $headers   —  Extra headers to send

[ Top ]

key   [line 680]

string key( )

Returns the key of the current element
  • Return: URL producing the response
  • Access: public

[ Top ]

next   [line 691]

void next( )

Moves forward to next element
  • Access: public

[ Top ]

post   [line 300]

integer post( string $url, mixed $data, [boolean $preEncoded = false], [array $files = array()], [array $headers = array()])

Sends a 'POST' HTTP request
  • Return: HTTP response code
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $url   —  URL
mixed   $data   —  Data to send
boolean   $preEncoded   —  Whether the data is already urlencoded
array   $files   —  Files to upload. Elements of the array should have the form: array(name, filename(s)[, content type]), see HTTP_Request::addFile()
array   $headers   —  Extra headers to send

[ Top ]

put   [line 330]

integer put( string $url, [string $body = ''], [array $headers = array()])

Sends a 'PUT' HTTP request
  • Return: HTTP response code
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $url   —  URL
string   $body   —  Request body
array   $headers   —  Extra headers to send

[ Top ]

reset   [line 507]

void reset( )

Clears object's internal properties
  • Access: public

[ Top ]

rewind   [line 702]

void rewind( )

Rewinds to the first element (response)
  • Access: public

[ Top ]

setDefaultHeader   [line 360]

void setDefaultHeader( mixed $name, [string $value = null])

Sets default header(s) for HTTP requests
  • Access: public

Parameters:

mixed   $name   —  header name or array ('header name' => 'header value')
string   $value   —  header value if $name is not an array

[ Top ]

setMaxRedirects   [line 200]

void setMaxRedirects( int $value)

Sets the maximum redirects that will be processed.

Setting this to 0 disables redirect processing. If not 0 and the number of redirects in a request is bigger than this number, then an error will be raised.

  • Access: public

Parameters:

int   $value   —  Max number of redirects to process

[ Top ]

setRequestParameter   [line 377]

void setRequestParameter( mixed $name, [string $value = null])

Sets parameter(s) for HTTP requests
  • Access: public

Parameters:

mixed   $name   —  parameter name or array ('parameter name' => 'parameter value')
string   $value   —  parameter value if $name is not an array

[ Top ]

valid   [line 714]

bool valid( )

Checks if there is a current element after call to rewind() or next()
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:26:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.