Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a XMLHTTP object

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to create XMLHTTP objects, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to create XMLHTTP objects. Let's take a look at it.

Microsoft.XMLHTTP objects are provided in MSXML, which can complete the conversion and sending tasks from data packets to Request objects.

The statement to create the XMLHTTP object is as follows:

Set objXML = CreateObject ("Msxml2.XMLHTTP") or

Set objXML = CreateObject ("Microsoft.XMLHTTP")

'Or for version 3.0of XMLHTTP, use:

After the creation of the 'Set objXML = Server.CreateObject ("MSXML2.ServerXMLHTTP") object, 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 (provided when the server needs to authenticate). The meaning of the parameter is as follows:

The way http-method:HTTP communicates, such as GET or POST

Url: the URL address of the server that received XML data. ASP or CGI programs are usually specified in URL

Async: a Boolean identity indicating whether the request is asynchronous. In the case of asynchronous communication (true), the client does not wait for a response from the server; in the case of synchronous communication (false), the client waits until the server returns a message before performing other operations

UserID: user ID for server authentication

Password: user password for server authentication

The Send method of XMLHTTP object

After initializing the Request object with the Open method, call the Send method to send XML data:

The parameter type of the objXML.send () Send method is Variant, which can be a string, a DOM tree, or any data stream.

There are two ways to send data: synchronous and asynchronous. In asynchronous mode, once the packet is sent, the Send process ends and the client performs other operations, while in synchronous mode, the client waits for the server to return an acknowledgement message before ending the Send process.

The readyState property in the XMLHTTP object

It can reflect the progress of the server in processing requests. The client's program can set the corresponding event handling method based on this state information. The property 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 finished

1 XML document has been loaded

2 the XML document has been loaded and is being processed

3 parts of XML documents have been parsed

4 the document has been parsed, and the client can accept the return message

The client processes the response information, and after receiving the return message, the client performs a simple processing, which basically completes an interaction cycle between Chand S.

The client receives the response through the properties of the XMLHTTP object:

ResponseText: use the return message as a text string

ResponseBody: returns the message as the content of the HTML document

ResponseXML: treat the return message as an XML document and use it when the server response message contains XML data

ResponseStream: treats the return message as a Stream object

Here is a simple example: similar to a news thief

The whole step is obvious: create, open, send, and accept.

This is the end of the article on "how to create XMLHTTP objects". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to create XMLHTTP objects". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report