Home > Backend Development > XML/RSS Tutorial > Detailed explanation of how to use XMLHTTP to send extremely long XML form data

Detailed explanation of how to use XMLHTTP to send extremely long XML form data

黄舟
Release: 2017-03-27 17:03:43
Original
1528 people have browsed it

When sending a large amount of XML as part of the POST data to your IIS server - such as in the TEXTAREA of the ASP form - you may get some expected results. When the data is processed on the server, you may end up encountering errors due to the way you process the data. The reason is that when you submit data back to the server, there is a (data) size limit in the POST field. The purpose of this is to prevent possible intruders from sending an extremely large amount of data to the server in a denial of service (DoS) attack.

This restriction also limits your ability. But there are ways around this problem. If you are not restricted to only sending data via FORM submission, then you can use XMLHTTPObject (a DOM Object in Microsoft's XML set) to send the required XML:

var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHTTP.open("POST", "xml_handler.asp", false);
oXMLHTTP.send(xml_to_send);
Copy after login

Since the Request object implements the IStream interface, you can load the XML to be submitted by using the load() method of the DOMDocument object:

Dim oDOM
Set oDOM = Server.CreateObject("MSXML2.DOMDocument")
oDOM.load Request
Copy after login

If You are limited to only submitting using FORM, so you can overcome this limitation by submitting multiple TEXTAREA or INPUT. The first two can be reassembled together as soon as the server receives the FORM data:

var MAXLEN = 90000;
var oForm = document.createElement("FORM");
oFORM.method = "POST";
oFORM.action = "xml_handler.asp";
oFORM = 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";
     o.name = "txtXML";
     o.value = s.substr(0, MAXLEN);
     oFORM.appendChild(o);
     s = s.substr(MAXLEN);
   }
   var o = document.createElement("INPUT");
   o.type = "hidden";
   o.name = "txtXML";
   o.value = s.substr(0, MAXLEN);
   oFORM.appendChild(o);
} else {
   var o = document.createElement("INPUT");
   o.type = "hidden";
   o.name = "txtXML";
   o.value = s;
   oFORM.appendChild(o);
}
Copy after login

This code will create a new FORM element to handle the submission of data and place it in the BODY element. It then checks the length of the XML that is about to be submitted to the server. This XML resides in a TEXTAREA called txtXML inside someForm.

If the XML is larger than the 90,000-character MAXLEN, then this code creates multiple hidden INPUT elements and sets the value's attribute to the 90,000-character XML data, or set to a value at the end of the XML to split the data into multiple parts. If the size of this XML is less than MAXLEN, then this code will just create an INPUT and set the value accordingly. This data is then submitted to the server for processing.

You may have noticed that I assigned the same name - txtXML - to each field of the new form. This will help separate the XML data from other data that may be submitted, and provide an easy way to reorganize the XML data. When reorganizing data, you need a simple loop to connect the data in the fields:

Dim str, fld
For Each fld In Request.Form("txtXML")
   str = str & fld
Next
Copy after login

Since a fields set has been created for each FORM element, you can Iterate over fields with the same name. As long as you create FORM elements on the client side in the proper order, you don't need to worry about the order in which the fields are traversed. This can be easily accomplished through FORM's appendChild() method.

Data is submitted in the order from left to right and top to bottom on the client, so when you append the INPUT element to the end of the FORM element, it will always be in the same order on your server. order to receive data.

If you are looking to implement a large data solution, such as transferring large amounts of Excel data from the client machine to the server, then you should reconsider whether to use FORM submission, or to logically transfer the data Divide into smaller parts. Since you cannot use the file type INPUT element, the most creative solution is to convert the data to XML locally and then submit the XML data to the server. In turn, the data is stored on the server until further processing is required.

Of course, there may be better ways to handle this problem. But when you don't have much time, all you need is a quick, usable solution.

The above is the detailed content of Detailed explanation of how to use XMLHTTP to send extremely long XML form data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template