Dotclear 2.24
|
HTTP Client. More...
Public Member Functions | |
__construct ($host, int $port=80, ?int $timeout=null) | |
get (string $path, $data=false) | |
post (string $path, $data, ?string $charset=null) | |
getStatus () | |
getContent () | |
getHeaders () | |
getHeader ($header) | |
getCookies () | |
getRequestURL () | |
setHost (string $host, int $port=80) | |
setProxy ($host, int $port=8080) | |
setTimeout (int $timeout) | |
setUserAgent (string $user_agent) | |
setAuthorization (?string $username, ?string $password) | |
setMoreHeader (string $header) | |
voidMoreHeaders () | |
setCookies (array $cookies) | |
useSSL (bool $flag) | |
useGzip (bool $flag) | |
setPersistCookies (bool $flag) | |
setPersistReferers (bool $flag) | |
setHandleRedirects (bool $flag) | |
setMaxRedirects (int $num) | |
setHeadersOnly (bool $flag) | |
setDebug (bool $flag) | |
setOutput (?string $out) | |
![]() | |
__construct (string $host, int $port, int $timeout=10) | |
__destruct () | |
host (?string $host=null) | |
port (?int $port=null) | |
timeout (?int $timeout=null) | |
setBlocking (bool $block) | |
open () | |
close () | |
write ($data) | |
flush () | |
isOpen () | |
Static Public Member Functions | |
static | quickGet (string $url, ?string $output=null) |
static | quickPost (string $url, array $data, ?string $output=null) |
static | initClient (string $url, string &$path) |
static | readURL (string $url, bool &$ssl, string &$host, int &$port, string &$path, string &$user, string &$pass) |
Protected Member Functions | |
buildQueryString ($data) | |
doRequest () | |
buildRequest () | |
outputOpen () | |
outputClose () | |
outputWrite ($content) | |
debug (string $msg, $object=false) | |
![]() | |
iterator () | |
Protected Attributes | |
$host | |
$port | |
$path | |
$method | |
$postdata = '' | |
$post_charset | |
$cookies = [] | |
$referer | |
$accept = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,image/webp,*/*' | |
$accept_encoding = 'gzip' | |
$accept_language = 'en-us' | |
$user_agent = 'Clearbricks HTTP Client' | |
$more_headers = [] | |
$timeout = 10 | |
$use_ssl = false | |
$use_gzip = false | |
$persist_cookies = true | |
$persist_referers = true | |
$debug = false | |
$handle_redirects = true | |
$max_redirects = 5 | |
$headers_only = false | |
$username | |
$password | |
$proxy_host | |
$proxy_port | |
$status | |
$status_string | |
$headers = [] | |
$content = '' | |
$redirect_count = 0 | |
$cookie_host = '' | |
$output = null | |
$output_h = null | |
![]() | |
$_host | |
$_port | |
$_transport = '' | |
$_timeout | |
$_handle | |
HTTP Client.
Features:
This class is fully based on Simon Willison's HTTP Client in version 0.9 of 6th April 2003 - http://scripts.incutio.com/httpclient/
Changes since fork:
__construct | ( | $host, | |
int | $port = 80 , |
||
?int | $timeout = null |
||
) |
Constructor.
Takes the web server host, an optional port and timeout.
string | $host | Server host |
int | $port | Server port |
int | $timeout | Connection timeout (in seconds) |
References $host, $port, $timeout, setHost(), setProxy(), and setTimeout().
get | ( | string | $path, |
$data = false |
|||
) |
GET Request
Executes a GET request for the specified path. If $data is specified, appends it to a query string as part of the get request. $data can be an array of key value pairs, in which case a matching query string will be constructed. Returns true on success.
string | $path | Request path |
bool | array | $data | Request parameters |
References $path, buildQueryString(), and doRequest().
post | ( | string | $path, |
$data, | |||
?string | $charset = null |
||
) |
POST Request
Executes a POST request for the specified path. If $data is specified, appends it to a query string as part of the get request. $data can be an array of key value pairs, in which case a matching query string will be constructed. Returns true on success.
string | $path | Request path |
array | string | $data | Request parameters |
string | $charset | Request charset |
References $path, buildQueryString(), and doRequest().
Referenced by akismet\callFunc(), htmlValidator\perform(), and akismet\verify().
|
protected |
|
protected |
Do Request
Sends HTTP request and stores status, headers, content object properties.
References $cookies, $host, $port, $proxy_host, $proxy_port, buildRequest(), netSocket\close(), debug(), getHeader(), getRequestURL(), netSocket\host(), netSocket\open(), outputClose(), outputOpen(), outputWrite(), netSocket\port(), setAuthorization(), setHost(), useSSL(), and netSocket\write().
Referenced by get(), post(), and xmlrpcClient\query().
|
protected |
Prepare Request
Prepares HTTP request and returns an array of HTTP headers.
Reimplemented in dcStoreReader, feedReader, and xmlrpcClient.
References $accept, $accept_encoding, $accept_language, $headers, $host, $path, $post_charset, $postdata, $referer, $user_agent, and getRequestURL().
Referenced by doRequest().
|
protected |
Open Output
Initializes output handler if $output
property is not null and is a valid resource stream.
Referenced by doRequest().
|
protected |
|
protected |
Write Output
Writes data to output module.
string | $content | Data content |
References $content.
Referenced by doRequest().
getStatus | ( | ) |
Get Status
Returns the status code of the response - 200 means OK, 404 means file not found, etc.
References $status.
Referenced by akismet\callFunc(), dcStoreReader\parse(), feedReader\parse(), htmlValidator\perform(), dcStoreReader\withCache(), and feedReader\withCache().
getContent | ( | ) |
Get Content
Returns the content of the HTTP response. This is usually an HTML document.
References $content.
Referenced by akismet\callFunc(), dcStoreReader\parse(), feedReader\parse(), htmlValidator\perform(), akismet\verify(), dcStoreReader\withCache(), and feedReader\withCache().
getHeaders | ( | ) |
Response Headers
Returns the HTTP headers returned by the server as an associative array.
References $headers.
getHeader | ( | $header | ) |
Response Header
Returns the specified response header, or false if it does not exist.
string | $header | Header name |
Referenced by doRequest().
getCookies | ( | ) |
getRequestURL | ( | ) |
Request URL
Returns the full URL that has been requested.
References $path, $port, netSocket\host(), and netSocket\port().
Referenced by buildRequest(), xmlrpcClient\buildRequest(), and doRequest().
setHost | ( | string | $host, |
int | $port = 80 |
||
) |
Sets server host and port.
string | $host | Server host |
int | $port | Server port |
References $host, $port, netSocket\host(), and netSocket\port().
Referenced by __construct(), doRequest(), feedReader\getFeed(), and dcStoreReader\getModulesXML().
setProxy | ( | $host, | |
int | $port = 8080 |
||
) |
Sets proxy host and port.
string | $host | Proxy host |
int | $port | Proxy port |
Referenced by __construct().
setTimeout | ( | int | $timeout | ) |
Sets connection timeout.
int | $timeout | Connection timeout (in seconds) |
References $timeout, and netSocket\timeout().
Referenced by __construct(), and dcStoreReader\__construct().
setUserAgent | ( | string | $user_agent | ) |
User Agent String
Sets the user agent string to be used in the request. Default is "Clearbricks HTTP Client".
string | $user_agent | User agent string |
References $user_agent.
Referenced by dcStoreReader\__construct().
setAuthorization | ( | ?string | $username, |
?string | $password | ||
) |
HTTP Authentication
Sets the HTTP authorization username and password to be used in requests. Don't forget to unset this in subsequent requests to different servers.
string | $username | User name |
string | $password | Password |
References $password, and $username.
Referenced by xmlrpcClient\__construct(), doRequest(), feedReader\getFeed(), and dcStoreReader\getModulesXML().
setMoreHeader | ( | string | $header | ) |
Add Header
Sets additionnal header to be sent with the request.
string | $header | Full header definition |
Referenced by htmlValidator\perform().
voidMoreHeaders | ( | ) |
Empty additionnal headers
setCookies | ( | array | $cookies | ) |
Set Cookies
Sets the cookies to be sent in the request. Takes an array of name value pairs.
array | $cookies | Cookies array |
References $cookies.
useSSL | ( | bool | $flag | ) |
Enable / Disable SSL
Sets SSL connection usage.
bool | $flag | Enable/Disable SSL |
Referenced by xmlrpcClient\__construct(), doRequest(), feedReader\getFeed(), and dcStoreReader\getModulesXML().
useGzip | ( | bool | $flag | ) |
Use Gzip
Specifies if the client should request gzip encoded content from the server (saves bandwidth but can increase processor time). Default behaviour is false.
bool | $flag | Enable/Disable Gzip |
setPersistCookies | ( | bool | $flag | ) |
Persistant Cookies
Specify if the client should persist cookies between requests. Default behaviour is true.
bool | $flag | Enable/Disable Persist Cookies |
setPersistReferers | ( | bool | $flag | ) |
Persistant Referrers
Specify if the client should use the URL of the previous request as the referral of a subsequent request. Default behaviour is true.
bool | $flag | Enable/Disable Persistant Referrers |
setHandleRedirects | ( | bool | $flag | ) |
Enable / Disable Redirects
Specify if the client should automatically follow redirected requests. Default behaviour is true.
bool | $flag | Enable/Disable Redirects |
setMaxRedirects | ( | int | $num | ) |
Maximum Redirects
Set the maximum number of redirects allowed before the client quits (mainly to prevent infinite loops) Default is 5.
int | $num | Maximum redirects value |
setHeadersOnly | ( | bool | $flag | ) |
Headers Only
If true, the client only retrieves the headers from a page. This could be useful for implementing things like link checkers. Defaults to false.
bool | $flag | Enable/Disable Headers Only |
setDebug | ( | bool | $flag | ) |
Debug mode
Should the client run in debug mode? Default behaviour is false.
bool | $flag | Enable/Disable Debug Mode |
References debug().
setOutput | ( | ?string | $out | ) |
Set Output
Output module init. If $out is null, then output will be directed to STDOUT.
string | null | $out | Output stream |
|
static |
|
static |
|
static |
Quick Init
Returns a new instance of the class. $path is an output variable.
string | $url | Request URL |
string | $path | Resulting path |
References $host, $path, and $port.
Referenced by dcUpdate\download(), dcStore\download(), dcUpdate\getVersionInfo(), dcFilterFairTrackbacks\isSpam(), and adminLangs\process().
|
static |
Read URL
Parses an URL and fills $ssl, $host, $port, $path, $user and $pass variables. Returns true on succes.
string | $url | Request URL |
boolean | $ssl | true if HTTPS URL |
string | $host | Host name |
int | $port | Server Port |
string | $path | Path |
string | $user | Username |
string | $pass | Password |
|
protected |
Debug
This method is the method the class calls whenever there is debugging information available. $msg is a debugging message and $object is an optional object to be displayed (usually an array). Default behaviour is to display the message and the object in a red bordered div. If you wish debugging information to be handled in a different way you can do so by creating a new class that extends netHttp and over-riding the debug() method in that class.
string | $msg | Debug message |
mixed | $object | Variable to print_r |
References debug().
Referenced by debug(), doRequest(), and setDebug().
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by xmlrpcClientMulticall\addCall(), and xmlrpcClient\query().
|
protected |
Referenced by buildRequest().
|
protected |
Referenced by buildRequest().
|
protected |
Referenced by doRequest(), getCookies(), and setCookies().
|
protected |
Referenced by buildRequest(), and akismet\callFunc().
|
protected |
Referenced by buildRequest().
|
protected |
Referenced by buildRequest().
|
protected |
Referenced by buildRequest().
|
protected |
Referenced by buildRequest(), xmlrpcClient\buildRequest(), and setUserAgent().
|
protected |
|
protected |
Referenced by __construct(), and setTimeout().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by setAuthorization().
|
protected |
Referenced by setAuthorization().
|
protected |
Referenced by doRequest().
|
protected |
Referenced by doRequest().
|
protected |
Referenced by getStatus().
|
protected |
|
protected |
Referenced by dcStoreReader\buildRequest(), feedReader\buildRequest(), buildRequest(), and getHeaders().
|
protected |
Referenced by akismet\callFunc(), akismet\comment_check(), getContent(), outputWrite(), akismet\submit_ham(), and akismet\submit_spam().
|
protected |
|
protected |
|
protected |
Referenced by quickGet(), and quickPost().
|
protected |