Code of XMLHTTPREQUEST Implementation HTTP request in PHP simulation ASP
Source: Internet
Author: User
Class Name: HttpRequest ($url = "", $method = "Get", $useSocket =0)
$url is the requested address; The default request method is get; $useSocket defaults to 0, use the Fsockopen method, or use the Socket_create method if set to 1
Method:
Open ($ip = "", $port =-1)//Open the connection to the server, the default do not set these two parameters (a colleague in Linux, the request is not hostname resolution of the IP, so add these two parameters to connect the real server IP)
settimeout ($timeout =0)//sets the timeout for obtaining data, which must be set before the Send method call, in seconds, and the default value of 0 is unrestricted
setRequestHeader ($key, $value = "")//Set request header, must be set before Send method call valid
Removerequestheader ($key, $value = "")//Remove the request header for the specified key value, which must be called before the Send method call is valid
Send ($data = "")//Send data $data to server
Getresponsebody ()//Get the text returned by the server
getAllResponseHeaders ()//Get all header information for server response
getResponseHeader ($key)//Get a header message for the server response, such as Server,set_cookie
Property:
$url//URL to request
$method//Request method (Post/get)
$port//Requested Port
$hostname//Requested host name
$uri//url part of the file
$protocol//Request Protocol (HTTP) (including all 5 properties of this property are automatically parsed by the program through the URL)
$excption//Exception information
$_headers=array ()//Request header Array ("Key" => "value")
$_senddata//data sent to the server
$status//Return status code
$statusText//status information
HTTP protocol version of the $HttpProtocolVersion//server
Attention:
The host header is automatically set by the program, and Content-length and Content-type are set automatically when the Post method is requested.
Pages that support gzip compression
Php_xmlhttprequest.rar
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service