MSXML provides Microsoft. XMLHTTP objects, which can complete conversion from 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 xml = server. Createobject ("msxml2.serverxmlhttp ")
After the object is created, the open method is called to initialize the request object. The syntax format is:
Poster. Open http-method, URL, async, userid, password
The open method contains five parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication ). The parameter meanings are as follows:
HTTP-method: the communication method of HTTP, such as get or post.
URL: the URL of the server that receives XML data. Generally, ASP or CGI must be specified in the URL. Program
Async: A boolean identifier indicating whether the request is asynchronous. If it is an asynchronous communication method (true), the client will not wait for the server's response; if it is a synchronous mode (false), the client will wait until the server returns a message to execute other operations
Userid, used for Server Authentication
Password, used for Server Authentication
Send method of XMLHTTP object
After initializing the request object using the open method, call the send method to send XML data:
Poster. Send XML-Data
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 asynchronous mode, once a packet is sent, the send process is terminated and the client performs other operations. In synchronous mode, the client waits until the server returns a confirmation message to terminate the send process.
The readystate attribute in the XMLHTTP object can reflect the progress of the server when processing requests. 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 description
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. The file has been parsed and the client can accept the returned message.
The client processes response information.
After the client receives the returned message, it simply processes it and basically completes an interaction cycle between C/S. The client receives the response through the attributes of the XMLHTTP object:
● Responsetxt: Use the returned message as a text string;
● Responsexml: regards the returned message as an XML document, which is used when the server response message contains XML data;
● Responsestream: regards the returned message as a stream object.
If you want to use a different browser, such as Firefox, then:
<Script language = JavaScript>
// The JB function initializes XMLHTTP Objects Based on Different browsers.
Function JB ()
{
VaR A = NULL;
Try
{
A = new activexobject ("msxml2.xmlhttp ");
}
Catch (E)
{
Try
{
A = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (OC)
{
A = NULL
}
}
If (! A & typeof XMLHttpRequest! = "Undefined ")
{
A = new XMLHttpRequest ()
}
Return
</SCRIPT>
It will return different XMLHTTP based on different browsers
For details, see:
Http://jibbering.com/2002/4/httprequest.html