SoFunction
Updated on 2025-03-02

Send extra long XML form data using XMLHTTP

When sending large amounts of XML to your IIS server as part of POST data—such as in TEXTAREA of ASP forms—you may get some unforeseen results. When data is processed on the server, you may end up encountering errors due to the different ways 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 huge amounts of data to the server during denial of service (DoS) attacks.

 
This limitation also binds your abilities. But there is a way to solve this problem. If you are not restricted to sending data only through FORM submissions, you can use XMLHTTP objects (a DOM object in Microsoft's XML set) to send the required XML:

var oXMLHTTP = new ActiveXObject("");
("POST", "xml_handler.asp", false);
(xml_to_send);

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 = ("")
Request

If you are restricted to being able to submit only FORM, you can overcome this limit by submitting multiple TEXTAREA or INPUTs. The first two can be recombined as soon as the server receives this FORM data:

var MAXLEN = 90000;
var oForm = ("FORM");
= "POST";
= "xml_handler.asp";
oFORM = (oFORM);
var s = ;
if ( > MAXLEN) {
    while ( > MAXLEN) {
        var o = ("INPUT");
        = "hidden";
        = "txtXML";
        = (0, MAXLEN);
        (o);
        s = (MAXLEN);
    }
    var o = ("INPUT");
    = "hidden";
    = "txtXML";
    = (0, MAXLEN);
    (o);
} else {
    var o = ("INPUT");
    = "hidden";
    = "txtXML";
    = s;
    (o);
}

This code creates a new FORM element to process the commit of the 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 someForm a TEXTAREA called txtXML.
 

If the XML is greater than 90,000 characters of MAXLEN, the code will create multiple hidden INPUT elements and set the value attribute to 90,000 characters of XML data, or set it to a value at the tail of the XML, thereby splitting the data into multiple parts. If the size of this XML 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 assigned the same name - txtXML - to each field of the new form. This will help separate XML data from other data that may be submitted and provide an easy way to reorganize XML data. When reorganizing data, you need a simple loop to connect the data in the field:

Dim str, fld
For Each fld In ("txtXML")
    str = str & fld
Next

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

Data is submitted on the client in order from left to right and top to bottom, so when you attach the INPUT element to the tail of the FORM element, the data is always received in the same order on your server.

If you are looking to implement a large data solution, such as passing large amounts of Excel data from a client machine to a server, then you should rethink whether to commit using FORM, or logically split the data into small sections. Since you can't use the file type INPUT element, the most creative solution is to convert the data locally into XML and then submit the XML data to the server. In turn, the data is saved on the server until further processing is needed.

Of course, there may be a better way to deal with this. But when you don't have much time, all you need is a quick, available solution.