Home  >  Article  >  Backend Development  >  PHP simulates XmlHttpRequest in asp to implement http request code_PHP tutorial

PHP simulates XmlHttpRequest in asp to implement http request code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:31:31881browse

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 , if set to 1, use the socket_create method

method:
open($ip="",$port=-1) //Open the connection to the same server, these two parameters do not need to be set by default ( When a colleague used Linux, he requested an IP that was not resolved by hostname, so he added these two parameters to connect to the real server IP)
setTimeout($timeout=0) //Set the timeout for obtaining data, It must be set before the send method is called to be effective. The unit is seconds. The default value is 0 for no limit
setRequestHeader($key,$value="") //Set the request header. It must be set before the send method is called to be effective
removeRequestHeader($key,$value="") //Remove the request header of the specified key value. It must be called before the send method is called to be effective
send($data="") //Send data $data to Server
getResponseBody() //Get the text returned by the server
getAllResponseHeaders() //Get all header information of the server response
getResponseHeader($key) //Get a certain header information of the server response, such as Server, Set_Cookie and other

attributes:
$url //URL to be requested
$method //Request method (POST/GET)
$port //Requested port
$hostname //The requested host name
$uri //The file part of the url
$protocol //The request protocol (http) (the above 5 attributes including this attribute are automatically analyzed 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
$HttpProtocolVersion //HTTP protocol version of the server

Note:
Host header is automatically set by the program. When requesting with POST method, Content -Length and Content-Type have been set automatically.
Page that supports gzip compression
php_XmlHttpRequest.rar

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323012.htmlTechArticleClass name: HttpRequest($url="",$method="GET",$useSocket=0) / /$url is the requested address; the default request method is GET; $useSocket defaults to 0, using the fsockopen method. If set to 1, use...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn