| Method Summary |
|
void
|
Constructor for initializing the class with default values.
|
|
void
|
Add a cookie to the request
|
|
void
|
Add request parameters
|
|
void
|
Clear Everything
|
|
string
|
execute
( string $target, string $referrer, string $method, array $data)
Execute a HTTP request
|
|
void
|
Whether to follow HTTP redirects
|
|
string
|
Get last execution error
|
|
array
|
Get execution result headers
|
|
string
|
Get execution result body
|
|
integer
|
Get execution status code
|
|
void
|
Initialize preferences
|
|
void
|
Whether to save persistent cookies in subsequent calls
|
|
void
|
setAuth
( string $username, string $password)
Set basic http authentication realm
|
|
void
|
Set cookie path (cURL only)
|
|
void
|
Set maximum number of redirection to follow
|
|
void
|
Set http method
|
|
void
|
Set request parameters
|
|
void
|
Set referrer URL
|
|
void
|
Set target URL
|
|
void
|
Set timeout of execution
|
|
void
|
Set User agent string
|
|
void
|
Whether to use cookies or not
|
|
void
|
Whether to use cURL or not
|
| Method Details |
Http
Constructor for initializing the class with default values.
|
addCookie
| public void addCookie |
(string $name , string $value ) |
Add a cookie to the request
| Input |
| string | $name | Name of cookie |
| string | $value | Value of cookie |
|
addParam
| public void addParam |
(string $name , string $value ) |
Add request parameters
| Input |
| string | $name | Name of the parameter |
| string | $value | Value of the parameter |
|
clear
Clear Everything
Clears all the properties of the class and sets the object to the beginning state. Very handy if you are doing subsequent calls with different data.
|
execute
| public string execute |
(string $target , string $referrer , string $method , array $data ) |
Execute a HTTP request
Executes the http fetch using all the set properties. Intellegently switch to fsockopen if cURL is not present. And be smart to follow redirects (if asked so).
| Input |
| string | $target | URL of the target page (optional) |
| string | $referrer | URL of the referrer page (optional) |
| string | $method | The http method (GET or POST) (optional) |
| array | $data | Parameter array for GET or POST (optional) |
| Output |
|
string
| Response body of the target page |
| Exception |
|
followRedirects
| public void followRedirects |
(boolean $value ) |
Whether to follow HTTP redirects
| Input |
| boolean | $value | Whether to follow HTTP redirects or not |
|
getError
| public string getError |
() |
Get last execution error
| Output |
|
string
| last error message (if any) |
| Exception |
|
getHeaders
| public array getHeaders |
() |
Get execution result headers
| Output |
|
array
| last headers of execution |
| Exception |
|
getResult
| public string getResult |
() |
Get execution result body
| Output |
|
string
| output of execution |
| Exception |
|
getStatus
| public integer getStatus |
() |
Get execution status code
| Output |
|
integer
| last http status code |
| Exception |
|
initialize
| public void initialize |
(array $config ) |
Initialize preferences
This function will take an associative array of config values and will initialize the class variables using them. Example use: $httpConfig['method'] = 'GET';
$httpConfig['target'] = 'http://www.somedomain.com/index.html';
$httpConfig['referrer'] = 'http://www.somedomain.com';
$httpConfig['user_agent'] = 'My Crawler';
$httpConfig['timeout'] = '30';
$httpConfig['params'] = array('var1' => 'testvalue', 'var2' => 'somevalue');
$http = new Http();
$http->initialize($httpConfig);
| Input |
| array | $config | Config values as associative array |
|
saveCookie
| public void saveCookie |
(boolean $value ) |
Whether to save persistent cookies in subsequent calls
| Input |
| boolean | $value | Whether to save persistent cookies or not |
|
setAuth
| public void setAuth |
(string $username , string $password ) |
Set basic http authentication realm
| Input |
| string | $username | Username for authentication |
| string | $password | Password for authentication |
|
setCookiepath
| public void setCookiepath |
(string $path ) |
Set cookie path (cURL only)
| Input |
| string | $path | File location of cookiejar |
|
setMaxredirect
| public void setMaxredirect |
(integer $value ) |
Set maximum number of redirection to follow
| Input |
| integer | $value | Maximum number of redirects |
|
setMethod
| public void setMethod |
(string $method ) |
Set http method
| Input |
| string | $method | HTTP method to use (GET or POST) |
|
setParams
| public void setParams |
(array $dataArray ) |
Set request parameters
| Input |
| array | $dataArray | All the parameters for GET or POST |
|
setReferrer
| public void setReferrer |
(string $referrer ) |
Set referrer URL
| Input |
| string | $referrer | URL of referrer page |
|
setTarget
| public void setTarget |
(string $url ) |
Set target URL
| Input |
| string | $url | URL of target resource |
|
setTimeout
| public void setTimeout |
(integer $seconds ) |
Set timeout of execution
| Input |
| integer | $seconds | Timeout delay in seconds |
|
setUseragent
| public void setUseragent |
(string $agent ) |
Set User agent string
| Input |
| string | $agent | Full user agent string |
|
useCookie
| public void useCookie |
(boolean $value ) |
Whether to use cookies or not
| Input |
| boolean | $value | Whether to use cookies or not |
|
useCurl
| public void useCurl |
(boolean $value ) |
Whether to use cURL or not
| Input |
| boolean | $value | Whether to use cURL or not |
|