Class http
Samples:
// GET $args = array(); $http = new http(); $http->m_trace_path = "./";
//Request Arguments from URI
if (!$http->getRequestArguments("http://localhost/request.php?test1=Hello&test2=World", $args))
echo "
".$http->m_error."
";
if (!$http->open($args))
echo "
".$http->m_error."
";
if (!$http->sendRequest($args))
echo "
".$http->m_error."
";
$headers = array();
if (!$http->readReplyHeaders($headers))
echo "
".$http->m_error."
";
$body = "";
$content = "";
for(;;)
{
if(!$http->readReplyBody($content,1000)){ echo "
".$http->m_error."
"; break;
} if(strlen($content) == 0){ break;
} $body .= $content;
}
if (!$http->close())
echo "
".$http->m_error."
";
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// GET with htaccess $args = array(); $http = new http();
$user = "username"; $pass = "password";
//Request Arguments from URI
if (!$http->getRequestArguments("http://".$user.":".$pass."@localhost/request.php?test1=Hello&test2=World", $args))
echo "
".$http->m_error."
";
if (!$http->open($args))
echo "
".$http->m_error."
";
if (!$http->sendRequest($args))
echo "
".$http->m_error."
";
$headers = array();
if (!$http->readReplyHeaders($headers)) // this function automatically calls the "authenticate" function when server sends HTTP 401 back
echo "
".$http->m_error."
";
$body = "";
$content = "";
for(;;)
{
if(!$http->readReplyBody($content,1000)){ echo "
".$http->m_error."
"; break;
} if(strlen($content) == 0){ break;
} $body .= $content;
}
if (!$http->close())
echo "
".$http->m_error."
";
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// POST $args = array(); $http = new http();
//Request Arguments from URI
if (!$http->getRequestArguments("http://localhost/request.php", $args))
echo "
".$http->m_error."
";
if (!$http->open($args))
echo "
".$http->m_error."
";
//Must the parameters manually change, otherwise a GET is sent as default $args["RequestMethod"] = "POST";
// POST fields $args["PostValues"]=array( "post1"=>"Hello", "post2"=>"World" );
//POST files $args["PostFiles"]=array( "userfile"=>array( "Data"=>"This is just a plain text attachment file named attachment.txt .", "Name"=>"attachment.txt", "Content-Type"=>"automatic/name", ), "anotherfile"=>array( "FileName"=>"test.log", "Content-Type"=>"automatic/name", ) );
if (!$http->sendRequest($args))
echo "
".$http->m_error."
";
$headers = array();
if (!$http->readReplyHeaders($headers))
echo "
".$http->m_error."
";
$body = "";
$content = "";
for(;;)
{
if(!$http->readReplyBody($content,1000)){ echo "
".$http->m_error."
"; break;
} if(strlen($content) == 0){ break;
} $body .= $content;
}
if (!$http->close())
echo "
".$http->m_error."
";
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// POST with htaccess $args = array(); $http = new http();
$user = "username"; $pass = "password";
//Request Arguments from URI
if (!$http->getRequestArguments("http://".$user.":".$pass."@localhost/request.php", $args))
echo "
".$http->m_error."
";
if (!$http->open($args))
echo "
".$http->m_error."
";
//Must the parameters manually change, otherwise a GET is sent as default $args["RequestMethod"] = "POST";
// POST fields $args["PostValues"]=array( "post1"=>"Hello", "post2"=>"World" );
//POST files $args["PostFiles"]=array( "userfile"=>array( "Data"=>"This is just a plain text attachment file named attachment.txt .", "Name"=>"attachment.txt", "Content-Type"=>"automatic/name", ), "anotherfile"=>array( "FileName"=>"test.log", "Content-Type"=>"automatic/name", ) );
if (!$http->sendRequest($args))
echo "
".$http->m_error."
";
$headers = array();
if (!$http->readReplyHeaders($headers)) // this function automatically calls the "authenticate" function when server sends HTTP 401 back
echo "
".$http->m_error."
";
$body = "";
$content = "";
for(;;)
{
if(!$http->readReplyBody($content,1000)){ echo "
".$http->m_error."
"; break;
} if(strlen($content) == 0){ break;
} $body .= $content;
}
if (!$http->close())
echo "
".$http->m_error."
";
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
//Redirect $args = array(); $http = new http();
//Request Arguments from URI
if (!$http->getRequestArguments("http://localhost/request.php?test1=Hello&test2=World", $args))
echo "
".$http->m_error."
";
if (!$http->open($args))
echo "
".$http->m_error."
";
$http->m_follow_redirect = true;
$args["location"] = "http://localhost/index.php";
if (!$http->redirect($args))
echo "
".$http->m_error."
";
$body = "";
$content = "";
for(;;)
{
if(!$http->readReplyBody($content,1000)){ echo "
".$http->m_error."
"; break;
} if(strlen($content) == 0){ break;
} $body .= $content;
}
if (!$http->close())
echo "
".$http->m_error."
";
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
//File Definition
if (!$http->getFileDefinition($args["PostFiles"]["userfile"],$definition)) - $definition has "Content-Type", "NAME", "DATA", and "Content-Length" from the file with the info in array given
echo "
".$http->m_error."
";
Methods summary
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
boolean
|
#
getRequestArguments( string $url, & $arguments, $getvars = "" )
parses URL string to get all necessary parameters (protocol, hostname, user, pass, port) |
public
boolean
|
|
public
boolean
|
|
public
|
|
public
boolean
|
#
getFileDefinition( array $file, & $definition )
fills out array $definition with information (Content-Type, Name, Data and Content-Length) from file vector (ex: used to send file as attachment) |
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
#
authenticate( boolean & $headers, string $proxy, string & $proxy_authorization, string $user, string $password, $realm, $workstation )
authenticates user either for proxy access or www access |
public
boolean
|
|
public
boolean
|
#
readReplyBody( integer & $body, $length )
reads HTTP Request Reply Body und fills out parameter variable |
public
|
#
saveCookies( string & $cookies, boolean $domain = '', boolean $secure_only = false, $persistent_only = false )
saves cookies |
public
|
#
savePersistentCookies( string & $cookies, boolean $domain = '', $secure_only = false )
saves always cookies as persistent - the same as calling saveCookies with last parameter = true |
public
|
#
getPersistentCookies( string & $cookies, boolean $domain = '', $secure_only = false )
saves always cookies as persistent - the same as calling saveCookies with last parameter = true |
public
boolean
|
#
restoreCookies( array $cookies, boolean $clear = true )
restore Cookies (clearing old Cookies or not) |
Properties summary
private
|
$m_logger
|
#
null
|
private
string
|
$m_state
|
#
"Disconnected"
|
private
integer
|
$m_use_curl
|
#
0
|
private
integer
|
$m_connection
|
#
0
|
private
integer
|
$m_content_length
|
#
0
|
private
string
|
$m_response
|
#
""
|
private
integer
|
$m_read_response
|
#
0
|
private
integer
|
$m_read_length
|
#
0
|
private
string
|
$m_request_host
|
#
""
|
private
string
|
$m_next_token
|
#
""
|
private
integer
|
$m_redirection_level
|
#
0
|
private
integer
|
$m_chunked
|
#
0
|
private
integer
|
$m_remaining_chunk
|
#
0
|
private
integer
|
$m_last_chunk_read
|
#
0
|
private
array
|
$m_months
|
#
array(
"Jan"=>"01",
"Feb"=>"02",
"Mar"=>"03",
"Apr"=>"04",
"May"=>"05",
"Jun"=>"06",
"Jul"=>"07",
"Aug"=>"08",
"Sep"=>"09",
"Oct"=>"10",
"Nov"=>"11",
"Dec"=>"12")
|
private
string
|
$m_session
|
#
''
|
private
integer
|
$m_connection_close
|
#
0
|
public
string
|
$m_host_name
request host name |
#
""
|
public
integer
|
$m_host_port
request host port |
#
0
|
public
string
|
$m_proxy_host_name
proxy host name |
#
""
|
public
integer
|
$m_proxy_host_port
proxy host port |
#
80
|
public
string
|
$m_protocol
request protocol (http or https) |
#
"http"
|
public
string
|
$m_request_method
request method (POST or GET) |
#
"GET"
|
public
string
|
$m_user_agent
request user-agent |
#
""
|
public
string
|
$m_authentication_mechanism
request authentication mechanism |
#
""
|
public
string
|
$m_user
user - RM: necessary? Later is this value in m_request_user saved and no more used |
|
public
string
|
$m_password
password - RM: necessary? Later is this value in m_request_password saved and no more used |
|
public
string
|
$m_realm
realm - RM: necessary? Later is this value in m_request_realm saved and no more used |
|
public
string
|
$m_workstation
workstation - RM: necessary? Later is this value in m_request_workstation saved and no more used |
|
public
string
|
$m_proxy_authentication_mechanism
proxy authentication mechanism - in case a proxy is used |
#
""
|
public
string
|
$m_proxy_user
proxy user - RM: necessary? Later is this value in m_proxy_request_user saved and no more used |
|
public
string
|
$m_proxy_password
proxy password - RM: necessary? Later is this value in m_proxy_request_password saved and no more used |
|
public
string
|
$m_proxy_realm
proxy realm - RM: necessary? Later is this value in m_proxy_request_realm saved and no more used |
|
public
string
|
$m_proxy_workstation
proxy workstation - RM: necessary? Later is this value in m_proxy_request_workstation saved and no more used |
|
public
string
|
$m_request_uri
request URI |
#
""
|
public
string
|
$m_request
request command |
#
""
|
public
array
|
$m_request_headers
request headers |
#
array()
|
public
string
|
$m_request_user
request user for authentication |
|
public
string
|
$m_request_password
request password for authentication |
|
public
string
|
$m_request_realm
request realm for authentication |
|
public
string
|
$m_request_workstation
request workstation for authentication |
|
public
string
|
$m_proxy_request_user
proxy user for authentication |
|
public
string
|
$m_proxy_request_password
proxy password for authentication |
|
public
string
|
$m_proxy_request_realm
proxy realm for authentication |
|
public
string
|
$m_proxy_request_workstation
proxy workstation for authentication |
|
public
string
|
$m_request_body
body |
#
""
|
public
array
|
$m_request_arguments
request arguments passed to sendRequest function |
#
array()
|
public
string
|
$m_protocol_version
protocol version |
#
"1.1"
|
public
integer
|
$m_timeout
timeout for connection - seconds - fsockopen or curl_setopt |
#
0
|
public
integer
|
$m_data_timeout
timeout for data stream - seconds |
#
0
|
public
boolean
|
$m_support_cookies
whether enable cookie support or not |
#
true
|
public
array
|
$m_cookies
cookies array |
#
array()
|
public
string
|
$m_error
error message - usually set by setError |
#
""
|
public
string
|
$m_exclude_address
address to which access is forbidden |
#
""
|
public
boolean
|
$m_follow_redirect
enable/disable redirect commands |
#
false
|
public
integer
|
$m_redirection_limit
maximum number of redirections |
#
5
|
public
string
|
$m_response_status
HTTP response status (ex: 200, 401, etc) |
#
""
|
public
string
|
$m_response_message
HTTP response message |
#
""
|
public
integer
|
$m_file_buffer_length
Buffer length in KBytes - to read stream data |
#
8000
|
public
boolean
|
$m_force_multipart_form_post
Force or not multipart form post in content-type header |
#
false
|
public
string
|
$m_trace_path
path for trace file |
#
""
|
public
string
|
$m_trace_file
filename of tracefile |
#
""
|
public
mixed
|
$m_trace_delAfter
size before trace file will set to zero |
#
"1024K"
|
public
string
|
$m_trace_critical_section_id
enable critical section for write trace files |
#
null
|
public
string
|
$m_trace_critical_section_path
path to share the critical section for write trace files |
#
"./"
|
public
integer
|
$m_trace_critical_section_maxlock_ms
max lock time for zombie processes |
#
1000
|
public
integer
|
$m_trace_critical_section_sleep_ms
sleep for retry enter critical section |
#
10
|
public
boolean
|
$m_force_resolve_ipv4_before_ipv6
fix routing problems with IPv6 (high start transfer time) |
#
true
|