XMLHTTP can send and receive strings, XML documents, arbitrary data streams

xiaoxiao2021-04-07  371

Zt http://www.itlearner.com/Article/2004/901.shtml

XMLHTTP objects and their methods ---------------- MSXML provides Microsoft.xmlhtttttttttp objects to complete the conversion from packets to the REQUEST object, and send tasks. The following statement creates XMLHTTP object: 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 ") Object creation After calling the Open method to initialize the Request object, the syntax format is: poster.open http-method, url, asken http-method, URL, ASYNC, UserId, the Password Open method contains 5 parameters, the top three are necessary The latter two is optional (provided when the server needs to be authenticated). The meaning of the parameter is as follows: http-method: HTTP communication method, such as a GET or POST URL: The URL address of the server that receives XML data. Typically in the URL to indicate an ASP or CGI program async: a Boolean identity, indicating whether the request is asynchronous. If it is asynchronous communication mode (TRUE), the client will not wait for the server response; if it is a synchronous mode (FALSE), the client will wait until the server returns the message to perform other operations Userid user ID, for server authentication Password User password, the Send method for server authentication XMLHTTP object After initialization of the REQUEST object with the Open method, call the Send method to send XML data: Poster.Send XML-Data Send method's parameter type is Variant, which can be a string, 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 has been loaded 2 XML document has been loaded, and the 3 part XML document has parsed 4 documents already After the analysis is complete, the client can accept the return message client to process the response information client to receive a return message, basically complete a interaction cycle between C / S. The client receiving response is implemented by the attribute of the XMLHTTP object: ● ResponseTxt: Take the message as a text string; ● ResponseXML: Use the return message as an XML document, use XML data in the server response message; ● ResponseStream: The return message is treated as a Stream object.

The following XML file is the dynamically generated final use of XMLHTTP. This is a content in the client JavaScript script, of course, you can also write in the server, but to change some things: (For your reference, understand it Usage) VAR Xmldoc = New ActiveXObject ("msxml2.domdocument"); flag = xmldoc.loadxml ("");

newNode = xmlDoc.createElement ( "encoded") 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 newNode.text = EndDate ( "EndDate"); DateNode.appendChild (newNode); newNode = xmlDoc.createElement ( "number") 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") Newn ode.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;

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

New Post(0)