Microsoft. XMLHTTP methods and attributes

Source: Internet
Author: User

Microsoft. XMLHttp component attributes
1. steps:
1. Create an XMLHTTP object // MSXML4.0 is required
2. Open the connection with the server, and define the command sending method, Service webpage (URL), and request permissions. The client opens a connection to the Service webpage of the server through the Open command. And pu
Like sending HTTP commands, you can use the "GET" method or "POST" method to point to the Service webpage of the server.
3. Send commands.
4. Wait for and receive the processing results returned by the server.
5. Release the XMLHTTP object

Ii. XMLHTTP method:
Open (bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword)
BstrMethod: data transmission method, that is, GET or POST.
BstrUrl: the URL of the Service webpage.
VarAsync: whether to run the command synchronously. The default value is True, that is, synchronous execution, but can only be performed in the DOM. Set it to true, that is, asynchronous execution.
BstrUser: user name, which can be omitted.
BstrPassword: user password, which can be omitted.

Send (varBody)
VarBody: instruction set. It can be XML data, a string, a stream, or an unsigned integer array. It can also be omitted, so that the command can be substituted by the URL parameter of the Open method.

SetRequestHeader (bstrHeader, bstrvalue)
Bstrheader: HTTP Header)
Bstrvalue: HTTP header value
If the open method is defined as post, you can define form upload:
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ")

Iii. XMLHTTP attributes:
Onreadystatechange: obtains the event handle of the returned result in synchronous execution mode. It can only be called in the Dom.
Responsebody: returns an unsigned integer array.
Responsestream: The returned result is an istream stream.
Responsetext: returns a string.
Responsexml: The returned result is in XML format.
Usage
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 (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. The ASP or CGI program is usually specified in the URL.
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: User ID, used for Server Authentication
Password: the user 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:

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 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.

ReadyState attribute in XMLHTTP object

It 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 the response information. After receiving the returned message, the client simply processes it and basically completes an interaction cycle between C/S.

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

ResponseText: uses the returned message as a text string;
ResponseBody: uses the returned message as the content of the HTML document;
ResponseXML: regards the returned message as an XML document, which is used when the server response message contains XML data;
ResponseStream: treats the returned message as a Stream object.

The following is a simple example: News thieves

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

 

Status

// Number: Description
// 100: Continue
/// 101: Switching protocols
/// 200: OK
/// 201: created
/// 202: accepted
// 203: Non-authoritative information
// 204: NO content
/// 205: reset content
// 206: Partial content
/// 300: Multiple Choices
// 301: moved permanently
/// 302: Found
// 303: see other
// 304: not modified
/// 305: use proxy
// 307: Temporary redirect
/// 400: Bad request
/// 401: unauthorized
// 402: payment required
/// 403: forbidden
// 404: not found
// 405: method not allowed
/// 406: Not acceptable
// 407: proxy authentication required
// 408: Request timeout
/// 409: Conflict
/// 410: Gone
/// 411: Length Required
/// 412: Precondition Failed
// 413: Request Entity Too Large
/// 414: Request-URI Too Long
// 415: Unsupported Media Type
// 416: Requested Range Not Suitable
/// 417: Expectation Failed
// 500: Internal Server Error
// 501: Not Implemented
/// 502: Bad Gateway
// 503: Service Unavailable
// 504: Gateway Timeout
// 505: HTTP Version Not Supported

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.