High-level HTTP request manager, which supports HTTP redirects, cookies and authentication.
More...
High-level HTTP request manager, which supports HTTP redirects, cookies and authentication.
- Examples:
- basic_http_authentication.php, basic_http_request_manager.php, http_cookies.php, and redirection_interception.php.
Constructor.
- Parameters
-
HttpSocket | $socket | Socket to use for requests |
HttpCookieManager | $cookie_manager | Cookie manager to use. Can be null. |
ICookieTimeProvider | $cookie_time_provider | Cookie time provider, can be passed to provide the time, which can be used for "expires" value calculation and for cookies expiration dates calculation. Can be null. |
addAuthData |
( |
|
$realm, |
|
|
|
$login, |
|
|
|
$password |
|
) |
| |
Adds authentication information for realm to allow automatic authentication (basic/digest) for it.
- Parameters
-
string | $realm | Realm name. If null, this function will set login and password for all non-listed realms |
string | $login | Login |
string | $password | Password |
Returns authentication information for realm.
- Parameters
-
string | $realm | Realm name. If null, this function will return login and password for all non-listed realms |
- Return values
-
Array | Array('login', 'password'). Can be null, if no authentication information present for realm |
Returns cookie manager.
- Return values
-
getMaxRedirectionCount |
( |
| ) |
|
Returns maximal HTTP redirection count. Default is 10.
- Return values
-
int | Maximal HTTP redirection count or -1 (unlimited redirects) |
getOnRedirectCallback |
( |
| ) |
|
Returns callback function that will be called before HTTP redirect occurs.
See setOnRedirectCallback also.
- Return values
-
callable | Callback function or null, if no HTTP redirect interception is needed |
Returns socket to use for requests.
- Return values
-
isAutomaticRefererUsed |
( |
| ) |
|
Returns true if automatic referer header set up is on for redirections.
- Return values
-
bool | True if automatic referer header set up is on for redirections |
Removes authentication information for realm.
- Parameters
-
string | $realm | Realm name. If null, this function will remove login and password for all non-listed realms |
Performs HTTP request.
May modify $request in case HTTP authentication will be required.
- Parameters
-
- Return values
-
- Exceptions
-
- Examples:
- redirection_interception.php.
Sets cookie manager.
- Parameters
-
setMaxRedirectionCount |
( |
|
$max_redirection_count | ) |
|
Sets maximal HTTP redirection count. Default is 10.
- Parameters
-
int | $max_redirection_count | Maximal HTTP redirection count or -1 (unlimited redirects) |
setOnRedirectCallback |
( |
callable |
$on_redirect = null | ) |
|
Sets callback function that will be called before HTTP redirect occurs.
The prototype of callback function:
Where:
$original_request is original WebRequest that lead to redirection response;
$response is server response;
$new_request is WebRequest that is going to be sent;
$http_code is HTTP redirection code;
$this is this request manager.
This function must return true to run redirect or false to abort it. If request is aborted from this callback, runRequest will return last WebResponse.
- Parameters
-
callable | $on_redirect | Callback function or null, if no HTTP redirect interception is needed |
Sets socket to use for requests.
- Parameters
-
useAutomaticReferer |
( |
|
$use_automatic_referer | ) |
|
Sets if automatic referer header set up is on for redirections.
- Parameters
-
int | $use_automatic_referer | If true, automatic referer header set up is on for redirections. |
The documentation for this class was generated from the following file: