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

Class: HTTP_Request

Source Location: /HTTP_Request-1.4.4/Request.php

Class Overview


Class for performing HTTP requests


Author(s):

Version:

  • Release: 1.4.4

Methods


Inherited Variables

Inherited Methods


Class Details

[line 121]
Class for performing HTTP requests

Simple example (fetches yahoo.com and displays it):

  1.  $a &new HTTP_Request('http://www.yahoo.com/');
  2.  $a->sendRequest();
  3.  echo $a->getResponseBody();



[ Top ]


Method Detail

HTTP_Request (Constructor)   [line 312]

HTTP_Request HTTP_Request( [string $url = ''], [array $params = array()])

Constructor

Sets up the object

  • Access: public

Parameters:

string   $url   —  The url to fetch/access
array   $params   —  Associative array of parameters which can have the following keys:
  • method - Method to use, GET, POST etc (string)
  • http - HTTP Version to use, 1.0 or 1.1 (string)
  • user - Basic Auth username (string)
  • pass - Basic Auth password (string)
  • proxy_host - Proxy server host (string)
  • proxy_port - Proxy server port (integer)
  • proxy_user - Proxy auth username (string)
  • proxy_pass - Proxy auth password (string)
  • timeout - Connection timeout in seconds (float)
  • allowRedirects - Whether to follow redirects or not (bool)
  • maxRedirects - Max number of redirects to follow (integer)
  • useBrackets - Whether to append [] to array variable names (bool)
  • saveBody - Whether to save response body in response object property (bool)
  • readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))
  • socketOptions - Options to pass to Net_Socket object (array)

[ Top ]

addCookie   [line 663]

void addCookie( string $name, string $value)

Appends a cookie to "Cookie:" header
  • Access: public

Parameters:

string   $name   —  cookie name
string   $value   —  cookie value

[ Top ]

addFile   [line 600]

bool addFile( string $inputName, mixed $fileName, [mixed $contentType = 'application/octet-stream'])

Adds a file to form-based file upload

Used to emulate file upload via a HTML form. The method also sets Content-Type of HTTP request to 'multipart/form-data'.

If you just want to send the contents of a file as the body of HTTP request you should use setBody() method.

  • Return: true on success
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $inputName   —  name of file-upload field
mixed   $fileName   —  file name(s)
mixed   $contentType   —  content-type(s) of file(s) being uploaded

[ Top ]

addHeader   [line 503]

void addHeader( string $name, string $value)

Adds a request header
  • Access: public

Parameters:

string   $name   —  Header name
string   $value   —  Header value

[ Top ]

addPostData   [line 554]

void addPostData( string $name, string $value, [bool $preencoded = false])

Adds postdata items
  • Access: public

Parameters:

string   $name   —  Post data name
string   $value   —  Post data value
bool   $preencoded   —  Whether data is already urlencoded or not, default = not

[ Top ]

addQueryString   [line 529]

void addQueryString( string $name, string $value, [bool $preencoded = false])

Adds a querystring parameter
  • Access: public

Parameters:

string   $name   —  Querystring parameter name
string   $value   —  Querystring parameter value
bool   $preencoded   —  Whether the value is already urlencoded or not, default = not

[ Top ]

addRawPostData   [line 627]

void addRawPostData( string $postdata, [bool $preencoded = true])

Adds raw postdata (DEPRECATED)
  • Deprecated: deprecated since 1.3.0, method setBody() should be used instead
  • Access: public

Parameters:

string   $postdata   —  The data
bool   $preencoded   —  Whether data is preencoded or not, default = already encoded

[ Top ]

addRawQueryString   [line 541]

void addRawQueryString( string $querystring, [bool $preencoded = true])

Sets the querystring to literally what you supply
  • Access: public

Parameters:

string   $querystring   —  The querystring data. Should be of the format foo=bar&x=y etc
bool   $preencoded   —  Whether data is already urlencoded or not, default = already encoded

[ Top ]

attach   [line 1076]

boolean attach( HTTP_Request_Listener &$listener)

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

Events sent by HTTP_Request object

  • 'connect': on connection to server
  • 'sentRequest': after the request was sent
  • 'disconnect': on disconnection from server
Events sent by HTTP_Response object
  • 'gotHeaders': after receiving response headers (headers are passed in $data)
  • 'tick': on receiving a part of response body (the part is passed in $data)
  • 'gzTick': on receiving a gzip-encoded part of response body (ditto)
  • 'gotBody': after receiving the response body (passes the decoded body in $data if it was gzipped)

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

Parameters:

HTTP_Request_Listener   &$listener   —  listener to attach

[ Top ]

clearCookies   [line 677]

void clearCookies( )

Clears any cookies that have been added (DEPRECATED).

Useful for multiple request scenarios

  • Deprecated: deprecated since 1.2
  • Access: public

[ Top ]

clearPostData   [line 651]

void clearPostData( )

Clears any postdata that has been added (DEPRECATED).

Useful for multiple request scenarios.

  • Deprecated: deprecated since 1.2
  • Access: public

[ Top ]

detach   [line 1093]

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 ]

disconnect   [line 836]

void disconnect( )

Disconnect the socket, if connected. Only useful if using Keep-Alive.
  • Access: public

[ Top ]

getResponseBody   [line 890]

mixed getResponseBody( )

Returns the body of the response
  • Return: response body, false if not set
  • Access: public

[ Top ]

getResponseCode   [line 850]

mixed getResponseCode( )

Returns the response code
  • Return: Response code, false if not set
  • Access: public

[ Top ]

getResponseCookies   [line 901]

mixed getResponseCookies( )

Returns cookies set in response
  • Return: array of response cookies, false if none are present
  • Access: public

[ Top ]

getResponseHeader   [line 874]

mixed getResponseHeader( [string $headername = null])

Returns either the named header or all if no name given
  • Return: either the value of $headername (false if header is not present) or an array of all headers
  • Access: public

Parameters:

string   $headername   —  The header name to return, do not set to get all headers

[ Top ]

getResponseReason   [line 861]

mixed getResponseReason( )

Returns the response reason phrase
  • Return: Response reason phrase, false if not set
  • Access: public

[ Top ]

getUrl   [line 434]

string getUrl( )

Returns the current request URL
  • Return: Current request URL
  • Access: public

[ Top ]

removeHeader   [line 514]

void removeHeader( string $name)

Removes a request header
  • Access: public

Parameters:

string   $name   —  Header name to remove

[ Top ]

reset   [line 399]

void reset( string $url, [array $params = array()])

Resets the object to its initial state (DEPRECATED).

Takes the same parameters as the constructor.

  • Deprecated: deprecated since 1.2, call the constructor if this is necessary
  • Access: public

Parameters:

string   $url   —  The url to be requested
array   $params   —  Associative array of parameters (see constructor for details)

[ Top ]

sendRequest   [line 690]

mixed sendRequest( [bool $saveBody = true])

Sends the request
  • Return: PEAR error on error, true otherwise
  • Access: public

Parameters:

bool   $saveBody   —  Whether to store response body in Response object property, set this to false if downloading a LARGE file and using a Listener

[ Top ]

setBasicAuth   [line 466]

void setBasicAuth( string $user, string $pass)

Sets basic authentication parameters

Parameters:

string   $user   —  Username
string   $pass   —  Password

[ Top ]

setBody   [line 638]

void setBody( string $body)

Sets the request body (for POST, PUT and similar requests)
  • Access: public

Parameters:

string   $body   —  Request body

[ Top ]

setHttpVer   [line 491]

void setHttpVer( string $http)

Sets the HTTP version to use, 1.0 or 1.1
  • Access: public

Parameters:

string   $http   —  Version to use. Use the defined constants for this

[ Top ]

setMethod   [line 480]

void setMethod( string $method)

Sets the method to be used, GET, POST etc.
  • Access: public

Parameters:

string   $method   —  Method to use. Use the defined constants for this

[ Top ]

setProxy   [line 448]

void setProxy( string $host, [int $port = 8080], [string $user = null], [string $pass = null])

Sets a proxy to be used
  • Access: public

Parameters:

string   $host   —  Proxy host
int   $port   —  Proxy port
string   $user   —  Proxy username
string   $pass   —  Proxy password

[ Top ]

setURL   [line 410]

void setURL( string $url)

Sets the URL to be requested
  • Access: public

Parameters:

string   $url   —  The url to be requested

[ Top ]


Documentation generated on Wed, 09 Dec 2015 22:39:03 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.