PHP WebSocket2 Library
PHP5 Library for browsing web
WebRequest Class Reference

Represents request that can be sent over HTTP(S) More...

Public Member Functions

 __construct ($address, $port=80, $method=self::METHOD_GET, $request_uri= '/', $url_encode=true)
 Constructor. More...
 
 isSecure ()
 Returns true if request is secure (HTTPS). More...
 
 getHeaderManager ()
 Returns request HTTP header manager. More...
 
 getParamManager ()
 Returns request HTTP parameter manager. More...
 
 getHttpVersion ()
 Returns HTTP version (see HTTP_VERSION_1_0 and HTTP_VERSION_1_1). More...
 
 getAddress ()
 Returns request address (hostname or IPv4 address). More...
 
 getMethod ()
 Returns request method. More...
 
 getPort ()
 Returns request port. More...
 
 getRequestUri ()
 Returns request URI. More...
 
 getRequestUriPath ()
 Returns request URI path portion. More...
 
 getFullAddress ($include_params=true)
 Returns full request URL. More...
 
 setSecure ($secure)
 Sets if request is secure (HTTPS). More...
 
 setHttpVersion ($version)
 Sets HTTP version (see HTTP_VERSION_1_0 and HTTP_VERSION_1_1). More...
 
 setAddress ($address)
 Sets request address (hostname or IPv4 address). More...
 
 setPort ($port)
 Sets request port. More...
 
 setMethod ($method)
 Sets request method. More...
 
 setRequestUri ($request_uri, $url_encode=true)
 Sets request URI. More...
 
 setBoundary ($boundary)
 Sets user-defined boundary for multipart/form-data requests. More...
 
 getBoundary ()
 Returns user-defined boundary for multipart/form-data requests. More...
 
 writeTo (HttpSocket $socket)
 Writes request to socket. More...
 
 setBasicAuthenticationCredentials ($login, $password)
 Adds basic authentication header. More...
 
 setDigestAuthenticationCredentials (Array $auth_opts, $login, $password)
 Adds digest authentication header. More...
 

Static Public Member Functions

static urlEncodeUri ($uri)
 Urlencodes request URI (each part of path separately). Does not accept absolute request URI's or request URI's with parameters. More...
 
static createFromUrl ($url, $url_encode_uri=true, $url_encode_params=true)
 Creates WebRequest. More...
 

Data Fields

const HTTP_VERSION_1_0 = 0
 HTTP version 1.0.
 
const HTTP_VERSION_1_1 = 1
 HTTP version 1.1.
 
const METHOD_GET = 'GET'
 GET request method.
 
const METHOD_POST = 'POST'
 POST request method.
 
const METHOD_CONNECT = 'CONNECT'
 CONNECT request method.
 
const METHOD_PUT = 'PUT'
 PUT request method.
 
const METHOD_HEAD = 'HEAD'
 HEAD request method.
 
const METHOD_TRACE = 'TRACE'
 TRACE request method.
 
const METHOD_DELETE = 'DELETE'
 DELETE request method.
 

Detailed Description

Represents request that can be sent over HTTP(S)

Examples:
redirection_interception.php, and response_interception.php.

Constructor & Destructor Documentation

__construct (   $address,
  $port = 80,
  $method = self::METHOD_GET,
  $request_uri = '/',
  $url_encode = true 
)

Constructor.

See createFromUrl also.
Default Connection is Close, default HTTP version is 1.0.
Connection will be secure in case port is 443.

Parameters
string$addressAddress of request (hostname or IPv4 address)
int$portPort of request
string$methodHTTP request method. See METHOD_GET, METHOD_POST, METHOD_CONNECT, METHOD_PUT, METHOD_HEAD, METHOD_TRACE, METHOD_DELETE
string$request_uriRelative request URI. IP:PORT is allowed for CONNECT method. HttpProxy will set absolute URI.
bool$url_encodeIf true, request URI string will be urlencoded

Member Function Documentation

static createFromUrl (   $url,
  $url_encode_uri = true,
  $url_encode_params = true 
)
static

Creates WebRequest.

Default Connection is Close, default HTTP version is 1.0.
Connection will be secure in case port is 443.

Parameters
string$urlFull request url
bool$url_encode_uriIf true, request URI path portion will be urlencoded (see urlEncodeUri)
bool$url_encode_paramsIf true, all parameter names and values will be urlencoded automatically
Return values
WebRequestWebRequest object
Exceptions
WebRequestExceptionin case of error
Examples:
basic_http_authentication.php, basic_http_request.php, basic_http_request_manager.php, basic_https_request.php, basic_proxy.php, http_cookies.php, http_file_upload.php, http_get_parameters.php, http_post_parameters.php, manual_http_authentication.php, proxy_authentication.php, proxy_chain.php, redirection_interception.php, response_interception.php, and timeouts.php.
getAddress ( )

Returns request address (hostname or IPv4 address).

Return values
stringRequest address (hostname or IPv4 address)
getBoundary ( )

Returns user-defined boundary for multipart/form-data requests.

Return values
stringUser-defined boundary or null, if boundary should be generated automatically. Default is null. Used only if request contains file attachments.
getFullAddress (   $include_params = true)

Returns full request URL.

Parameters
bool$include_paramsIf true, GET parameters will be included to URLs
Return values
stringFull request URL
Examples:
redirection_interception.php, and response_interception.php.
getHeaderManager ( )

Returns request HTTP header manager.

Return values
HttpHeaderManagerRequest HTTP header manager
getHttpVersion ( )

Returns HTTP version (see HTTP_VERSION_1_0 and HTTP_VERSION_1_1).

Return values
intHTTP version
getMethod ( )

Returns request method.

See METHOD_GET, METHOD_POST, METHOD_CONNECT, METHOD_PUT, METHOD_HEAD, METHOD_TRACE, METHOD_DELETE

Return values
stringRequest method
getParamManager ( )

Returns request HTTP parameter manager.

Return values
HttpParamManagerRequest HTTP parameter manager
getPort ( )

Returns request port.

Return values
intRequest port
getRequestUri ( )

Returns request URI.

Return values
stringRequest URI
getRequestUriPath ( )

Returns request URI path portion.

Returns empty string in case of CONNECT method.

Return values
stringRequest URI path portion
isSecure ( )

Returns true if request is secure (HTTPS).

Return values
boolTrue if request is secure (HTTPS)
setAddress (   $address)

Sets request address (hostname or IPv4 address).

Parameters
string$addressRequest address (hostname or IPv4 address)
setBasicAuthenticationCredentials (   $login,
  $password 
)

Adds basic authentication header.

Parameters
string$loginLogin
string$passwordPassword
setBoundary (   $boundary)

Sets user-defined boundary for multipart/form-data requests.

Parameters
string$boundaryUser-defined boundary or null, if boundary should be generated automatically. Default is null. Used only if request contains file attachments.
setDigestAuthenticationCredentials ( Array  $auth_opts,
  $login,
  $password 
)

Adds digest authentication header.

Parameters
Array$auth_optsAuthentication data returned by HttpHeaderManager::getAuthenticationOptions
string$loginLogin
string$passwordPassword
Exceptions
WebRequestExceptionin case of error in options
setHttpVersion (   $version)

Sets HTTP version (see HTTP_VERSION_1_0 and HTTP_VERSION_1_1).

Parameters
int$versionHTTP version
setMethod (   $method)

Sets request method.

See METHOD_GET, METHOD_POST, METHOD_CONNECT, METHOD_PUT, METHOD_HEAD, METHOD_TRACE, METHOD_DELETE

Parameters
string$methodRequest method
setPort (   $port)

Sets request port.

Parameters
int$portRequest port
setRequestUri (   $request_uri,
  $url_encode = true 
)

Sets request URI.

Parameters
string$request_uriRequest URI
bool$url_encodeIf true, request URI string will be urlencoded
setSecure (   $secure)

Sets if request is secure (HTTPS).

Parameters
bool$secureTrue to set request secure (HTTPS)
static urlEncodeUri (   $uri)
static

Urlencodes request URI (each part of path separately). Does not accept absolute request URI's or request URI's with parameters.

Parameters
string$uriRequest URI
Return values
stringUrlencoded request URI.
writeTo ( HttpSocket  $socket)

Writes request to socket.

Parameters
HttpSocket$socketSocket to write request to
Exceptions
WebRequestExceptionin case of any errors

The documentation for this class was generated from the following file: