Detailed explanation of Microsoft's XMLHTTP object

黄舟
Release: 2017-03-16 16:32:50
Original
1470 people have browsed it

Microsoft.XML

HTTP object is provided in MSXML, 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 MSXML provides the Microsoft.XMLHTTP object, 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") 或
Set objXML = CreateObject("Microsoft.XMLHTTP")
'Or for version 3.0 of XMLHTTP, use:
Copy after login

'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
Copy after login


The Open method contains 5 parameters. The first three are necessary, and the last two are optional (provided when server requires authentication). The meaning of the parameters is as follows:
http-method: HTTP communication method, such as GET or POST
url: Server that receives XML data URL address. Usually ASP or CGI program
async should be specified in the URL: A Boolean identifier indicating whether the request is asynchronous. If it is an asynchronous communication mode (true), the client will not wait for the response from the server ; if it is a synchronous mode (false), the client will wait until the server returns the message before executing it. 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
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 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: Return the message as a text string;
responseBody:Return the message as HTML document Content;
responseXML: Treat the return message as an XML document, used when the server response message contains XML data;
responseStream: Treat the return message as a Stream object
Here is a simple example: Similar to News Thief

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

The whole steps are obvious: create, open, send and receive.                                                                                              

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

Related labels:
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!