Php simulates XmlHttpRequest in asp to implement http request code

Source: Internet
Author: User
To simulate the phphttp request class written by the xmlhttp component in asp, the basic functions are implemented. The gzip compression class name is supported: HttpRequest ($ url = "", $ method = "GET", $ useSocket = 0)
// $ Url indicates the request address. the default request method is GET. $ useSocket defaults to 0 and fsockopen is used. if it is set to 1, socket_create is used.

Method:
Open ($ ip = "", $ port =-1) // open the connection to the same server. by default, you do not need to set these two parameters (when a colleague is using linux, the requested IP address is not resolved by the hostname. Therefore, these two parameters are added to connect to the real server IP address)
SetTimeout ($ timeout = 0) // sets the time-out time for data retrieval. The value is valid only before the send method is called. the default value is 0, which is unlimited.
SetRequestHeader ($ key, $ value = "") // sets the request header, which must be set before the send method is called.
RemoveRequestHeader ($ key, $ value = "") // removes the request header with the specified key value, which must be called before the send method is called.
Send ($ data = "") // send $ data to the server
GetResponseBody () // get the text returned by the server
GetAllResponseHeaders () // get all the header information of the server response
GetResponseHeader ($ key) // Obtain a header of the Server response, such as Server and Set_Cookie.

Attribute:
$ Url // the url to be requested
$ Method // request method (POST/GET)
$ Port // request port
$ Hostname // the requested host name
$ Uri // The File part of the url
$ Protocol // request protocol (http) (more than five attributes including this attribute are automatically analyzed by the program through url)
$ Excption // exception information
$ _ Headers = array () // request header array ("key" => "value ")
$ _ Senddata // data sent to the server
$ Status // returned status code
$ StatusText // status information
$ HttpProtocolVersion // HTTP protocol version of the server

Note:
The Host header is automatically set by the program. when a POST request is used, Content-Length and Content-Type are automatically set.
Pages that support gzip compression
Php_XmlHttpRequest.rar

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.