MSXML provides Microsoft. XMLHTTP objects, which can convert data packets to Request objects and send tasks. The statement for creating an XMLHTTP object is as follows: SetobjXML = CreateObject (Msxml2.XMLHTTP) or SetobjXML = CreateObject (Microsoft. XML MSXML provides Microsoft. XMLHTTP objects, which can convert data packets to Request objects and send tasks.
The statement for creating an XMLHTTP object is 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, the Open method is called to initialize the Request object. the syntax format is:
ObjXML. open http-method, url, async, userID, password
The Open method contains five parameters, the first three are necessary, and the last two are optional (ServerRequired for identity authentication ). The parameter meanings are as follows:
Http-method:HTTP communication methods, such as GET or POST
Url:Receiving XML dataServer. The ASP or CGI program is usually specified in the URL.
Async:A Boolean identifier that specifies whether the request is asynchronous. If it is an asynchronous communication method (true), the client will not waitServerIf it is a synchronous method (false), the client will waitServerOther controllers are performed only after a message is returned.
UserID:User ID, usedServerAuthentication
Password:User password, usedServerAuthentication
Send method of XMLHTTP object
After initializing the Request object using 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.
Data transmission methods can be synchronous or asynchronous. In the asynchronous method, once the data packet is sent, the Send process ends and the client performs other control operations. in the synchronous method, the client waits
ServerThe Send process ends only after a confirmation message is returned.
ReadyState attribute in XMLHTTP object
It can reflect
ServerThe progress of the request. The client program can set corresponding event handling methods based on the status information. The attribute values and their meanings are shown in the following table:
Value clarification
0 Response object has been created, but the XML document upload process has not been completed
1. the XML document has been loaded.
2. the XML file has been loaded and is being processed.
3. some XML documents have been parsed.
4. after the documents have been parsed, the client can receive the returned messages.
The client processes the response information. after receiving the returned message, the client simply processes the response and completes an interaction cycle between C/S.
The client receives the response through the attributes of the XMLHTTP object:
ResponseText:Use the returned message as a text string;
ResponseBody:Use the returned message as the HTML document content;
ResponseXML:The returned message is treated as an XML document.ServerApplication when the response message contains XML data;
ResponseStream:The returned message is treated as a Stream object.
The following is a simple example: message thieves
<%
Set objXML = Server. CreateObject ("MSXML2.ServerXMLHTTP ")
ObjXML. open "GET", "http://www.alexa.com", false
ObjXML. send ()
Response. write (objXML. responseText)
%>
The steps are obvious: Create, open, send, and receive.