Introduction to the Microsoft.XMLHTTP object

PHPz
Release: 2017-04-02 11:18:01
Original
2033 people have browsed it

Microsoft.XMLHTTPobject is provided in MSXML, which can complete the conversion and sending tasks from data packets to Request objects. The statement to create an XMLHTTP object is as follows: Set objXML = CreateObject("Msxml2.XMLHTTP") or Set objXML = CreateObject("Microsoft.XMLHTTP")'Or for version 3.0 of

MSXML The Microsoft.XMLHTTP object is provided, which can complete the conversion and sending tasks from data packets to Request objects.
The statements to create an XMLHTTP object are as follows:

Set objXML = CreateObject("Msxml2.XMLHTTP") or
Set objXML = CreateObject("Microsoft.XMLHTTP")
'Or for version 3.0 of XMLHTTP, use:
'Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP") After the object is created, call the Open method to initialize the Request object. The syntax format is:

objXML.open http-method ,url,async,userID,password
The Open method contains 5 parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication). The meaning of the parameters is as follows:
http-method: HTTP communication method, such as GET or POST
url: The URL address of the server that receives XML data. Usually the ASP or CGI program should be specified in the URL
async: a Boolean identifier indicating whether the request is asynchronous. If it is an asynchronous communication mode (true), the client does not wait for the server's response; if it is a synchronous mode (false), the client has to wait until the server returns a message before performing other operations
userID: user ID, used for Server authentication
password: user password, used for server authentication
Send method of XMLHTTP object
After initializing the Request object with the Open method, call the Send method to send XML data:
objXML.send () The parameter type of the Send method is Variant, which can be a string, DOM tree or any data stream.
There are two ways to send data: synchronous and asynchronous. In asynchronous mode, once the data packet is sent, the Send process is ended and the client performs other operations; in synchronous mode, the client waits until the server returns a confirmation message before ending the Send process.
The readyState attribute in the XMLHTTP object
It can reflect the progress of the server in processing the request. The client program can set the corresponding event processing method based on this status information. The attribute values ​​and their meanings are shown in the following table:

Value Description
0 The Response object has been created, but the XML document upload process has not yet ended
1 The XML document has been loaded
2 The XML document has been loaded Loading completed and being processed
3 Part of the XML document has been parsed
4 The document has been parsed and the client can accept the return message
The client processes the response information. After the client receives the return message, it performs a simple Processing basically completes an interaction cycle between C/S.
The client receives the response through the properties of the XMLHTTP object:
responseText: returns the message as a text string;
responseBody: returns the message as HTML document content;
responseXML: returns the message Treated as an XML document, used when the server response message contains XML data;
responseStream: treat the return message as a Stream object
The following is a simple example: similar to the news thief

<%
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.open "GET","http://www.php.cn",false
objXML.send()
response.write(objXML.responseText)
%>
Copy after login

The steps are obvious: create, open, send and accept.

The above is the detailed content of Introduction to the Microsoft.XMLHTTP object. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!