XMLHTTP object and method thereof

zhaozj2021-02-16  128

Microsoft.xmlHTTP objects are provided in MSXML to complete the conversion from packets to the REQUEST object, and send tasks.

Creating a statement for the XMLHTTP object is as follows:

Set objxml = creteObject (msxml2.xmlhttp) or

Set objxml = creteObject ("Microsoft.xmlhttp")

'OR, for Version 3.0 of XMLHTTP, USE:

'Set XML = Server.createObject (msxml2.serverxmlhttp)

The OPEN method is called after the object is created, and the REQUEST object is initialized. The syntax format is:

Poster.open http-method, url, async, userid, password

The OPEN method contains 5 parameters, the top three are necessary, the latter two are optional (provided when the server needs to be authenticated). 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 you want to specify an ASP or CGI program in the URL

ASYNC: A Boolean identifier indicating whether the request is asynchronous. If it is asynchronous communication mode, the client will not wait for the server's response; if it is a synchronization mode (FALSE), the client will wait until the server returns a message before performing other operations.

UserID user ID for server authentication

Password user password for server authentication?

XMLHTTP object SEND method

After initialization of the Request object with 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, a DOM tree, or any data stream. The way to send data is divided into synchronous and asynchronous. In an asynchronous mode, once the data package is sent, end the Send process, the client performs other operations; and in the synchronization mode, the client will wait until the server returns a confirmation message to end the Send process.

The ReadyState property in the XMLHTTP object reflects the progress of the server during processing the request. The program of the client can set the corresponding event processing method according to this status information. The attribute value and its meaning are shown in the following table:

Value description

0 Response object has been created, but the XML document upload process has not ended

1 XML document is already loaded

2 XML document is already loaded, it is processing

3 section XML document has been parsed

4 Documents have been parsed, and the client can accept the return message.

Client Processive Response Information

After receiving the return message, the client is received, and there is basically a interactive cycle between C / S. The client receiving response is implemented by the properties of the XMLHTTP object:

● Responsetxt: The message will return as a text string;

● ResponseXML: Treat the return message as an XML document, use XML data in the server response message;

● ResponseSteram: Treats the return message as a Stream object.

转载请注明原文地址:https://www.9cbs.com/read-7834.html

New Post(0)