Send long XML form data using XMLHTTP

xiaoxiao2021-03-06  94

When sending a large number of XMLs as part of the POST data - such as TEXTAREA in the ASP form - you might get some unpredictable results. When the data is processed on the server, you may eventually touch the error because you process the data mode. The reason is that when you submit the data back to the server, there is a (data) limit in the Post field. The purpose of doing this is to prevent possible intruders from sending an exceeding a large amount of data to the server in the implementation of the Denial of Service, DOS.

This limitation also binds your ability. But there is a way to solve this problem. If you are not restricted to send data by Form, you can use XMLHTTP objects (a DOM object in Microsoft XML set) to send the required XML: var oxmlhttp = new activXObject ("Microsoft.xmlhttp "); oxmlhttp.Open (" post "," xml_handler.asp ", false); oxmlhttp.send (XML_TO_SEND); Since the Request object implements the ISTREAM interface, you can load the ToAd () method of the DomDocument object. Submitted XML: Dim OdomSet = Server.createObject ("msxml2.domdocument") odom.Load Request If you are limited to use Form Submit, you can span this by submitting multiple Textarea or Input, front When both the server receives this Form data, it can be recombined together: var maxlen = 90000; var oform = document.createElement ("form"); lym.method = "post"; lym.action = " XML_Handler.asp "; = document.body.Appendchild (OFORM); var s = document.someform.txtXml.value; if (s.Length> Maxlen) {while (s.Length> maxlen) {var o = document. CreateElement ("Input"); o.Type = "hidden"; .name = "txtXml"; o.value = s.substr (0, maxlen); = sAppendchild (O); s = s.substr (Maxlen ); Var o = document.createElement ("input"); o.Type = "hidden"; .name = "txtXml"; o.value = s.substr (0, Maxlen);} else {var o = document.createElement ("infut"); o.Type = "hidden"; o.Name = "txtXml"; o.value = s; Oform.Appendchild (O);} This code creates a new FORM element to process data submission and place it into the body element. Then, it will check the length of XML that is about to be submitted to the server. This XML resides in the TEXTAREA called txtXML inside the Someform.

If this XML is greater than 90,000 characters, then this code creates multiple hidden input elements, and sets the value of the value to 90,000 characters XML data, or set to a value of the XML tail, Thereby this data is divided into multiple parts. If this XML size is smaller than maxlen, then this code will only create an input and set the value accordingly. Then this data is submitted to the server for processing. You may have noticed that I specify the same name --TXTXML - specify each field of the new form. This will help to separate XML data to other data that may be submitted, and provide a simple way for restructuring XML data. When reorganizing data, you need a simple loop to connect data in the field: DIM STR, FLDFOR EACH FLD IN Request.form ("txtXML") Str = Str & FldNext Since all FORM elements have been created Field set, so you can iterate in the field of the same name. As long as you create a FORM element in the client in an appropriate order, you don't need to worry about the order of the field being traversed. This can be easily implemented by the AppendChild () method of form.

The data is submitted from left to right, from top to bottom, so when you attach the INPUT element to the end of the FORM element, you always receive data in the same order in your server. .

If you are seeking a large data solution, such as passing a lot of Excel data from the client machine to the server, then you should reconsider whether you want to use Form to submit, or divide the data from multiple small parts . Since you cannot use the file type INPUT element, the most creative solution is to convert the data into XML, and then submit XML data to the server. Conversely, the data will be saved on the server until it needs to be processed.

Of course, it may have a better way to deal with this problem. But when you don't have much time, what you need is a fast, available solution.

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

New Post(0)