XMLHTTP objects and their methods————————————————————————
MSXML provides the Microsoft.XMLHTTP object, which can complete the conversion and sending tasks from data packets to Request objects.
The statement to create 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, call the Open method to initialize the Request object. The syntax format is:
poster.open http-method, url, async, userID, password
The Open method contains 5 parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication). 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 the ASP or CGI program is specified in the URL
async: A Boolean flag indicating whether the request is asynchronous. If it is asynchronous communication mode (true), the client does not wait for the server's response; if it is synchronous mode (false), the client has to wait until the server returns a message before performing other operations.
userID User ID used for server authentication
password User password, used for server authentication
After the Send method of the XMLHTTP object initializes the Request object with the Open method, call the Send method to send the 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. There are two ways to send data: synchronous and asynchronous. In asynchronous mode, once the data packet is sent, the Send process is ended, and the client performs other operations; in synchronous mode, the client waits until the server returns a confirmation message before ending the Send process.
The readyState attribute in the XMLHTTP object can reflect the progress of the server in processing the request. The client program can set the corresponding event processing method based on this status information. The attribute values and their meanings are shown in the following table:
Value description
0 The Response object has been created, but the XML document upload process has not yet ended.
1 The XML document has been loaded
2 The XML document has been loaded and is being processed.
3 Part of the XML document has been parsed
4 The document has been parsed and the client can accept the return message. The client processes the response information. After receiving the return message, the client performs simple processing, which basically completes an interaction cycle between C/S. The client receives the response through the properties of the XMLHTTP object:
● responseTxt: return the message as a text string;
● responseXML: treat the return message as an XML document, used when the server response message contains XML data;
● responseStream: treat the returned message as a Stream object.
The following xml file is dynamically generated and finally sent out using xmlHTTP. This is the content in the client JavaScript script. Of course, you can also write it on the server, but you need to change some things accordingly: (For your reference only, understand it usage)
var xmlDoc=new ActiveXObject("MSXML2.DOMDocument");
flag=xmlDoc.loadXML("");
newNode =xmlDoc.createElement("encoding")
MarkNode=xmlDoc.documentElement.appendChild(newNode);
newNode =xmlDoc.createElement("StartMark")
newNode.text=StartMark;
MarkNode.appendChild(newNode)
newNode =xmlDoc.createElement("EndMark")
newNode.text=EndMark;
MarkNode.appendChild(newNode)
newNode =xmlDoc.createElement("Date")
DateNode=xmlDoc.documentElement.appendChild(newNode);
newNode =xmlDoc.createElement("StartDate");
newNode.text=StartDate;
DateNode.appendChild(newNode)
newNode =xmlDoc.createElement("EndDate")
newNode.text=EndDate;
DateNode.appendChild(newNode);
newNode =xmlDoc.createElement("Quantity")
SLNode =xmlDoc.documentElement.appendChild(newNode);
newNode =xmlDoc.createElement("StartSL")
newNode.text=StartShuL
SLNode.appendChild(newNode)
newNode =xmlDoc.createElement("EndSL");
newNode.text=EndShuL
SLNode.appendChild(newNode);
newNode =xmlDoc.createElement("unit price")
DJNode =xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("StartDJ")
newNode.text=StartDanJ;
DJNode.appendChild(newNode);
newNode =xmlDoc.createElement("EndDJ")
newNode.text=EndDanJ;
DJNode.appendChild(newNode);
newNode =xmlDoc.createElement("amount")
JENode =xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("StartJE")
newNode.text=StartJinE
JENode.appendChild(newNode)
newNode =xmlDoc.createElement("EndJE")
newNode.text=EndJinE
JENode.appendChild(newNode)
newNode =xmlDoc.createElement("warehouse code")
newNode.text=CK;
xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("ticket number")
newNode.text=RKPH;
xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("unit code")
newNode.text=CorpName;
xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("BiaoShi")
newNode.text=Biaoshi
xmlDoc.documentElement.appendChild(newNode)
newNode =xmlDoc.createElement("FindCate")
newNode.text=FindCate
xmlDoc.documentElement.appendChild(newNode)
var xh =new ActiveXObject("MSXML2.XMLHTTP")
xh.open("POST","Find.asp",false)
xh.setRequestHeader("Content-Type","text/xml")
xh.setRequestHeader("Content-Type","gb2312")
xh.send(xmlDoc);
The text value of each of my newNode is a variable, which is the value input in my client form.