Home > Backend Development > XML/RSS Tutorial > Details of sending very long XML form data using XMLHTTP

Details of sending very long XML form data using XMLHTTP

黄舟
Release: 2017-03-04 17:24:47
Original
1374 people have browsed it

When sending a large amount of xml to your IIS server as part of the POST data - such as in the TEXTAREA of an asp form - you may get some unexpected 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 limited to sending data via FORM submission, then you can use the xmlhttp object (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 restricted to only submitting using FORM, then you This limitation can be overcome by submitting multiple TEXTAREA or INPUT. The first two can be reassembled 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 data submission 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 will create multiple hidden INPUT elements and set the value 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 the 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 fieldset has been created for each FORM element, so 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 from left to right and top to bottom on the client side, so when you append the INPUT element to the end of the FORM element, it will always Data is received in the same order.

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 transfer the data logically 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 details of using XMLHTTP to send ultra-long XML form data. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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