Detailed description of how to send ultra-long XML form data using XMLHTTP

Source: Internet
Author: User
When a large amount of xml is sent to your IIS server as part of the POST data, such as in the TEXTAREA of the asp form, you may get unexpected results. When data is processed on the server, you may encounter errors due to different data processing methods. The reason is that when you submit data back to the server, there is a (data) size limit in the POST field. This aims to prevent possible intruders from sending large amounts of data to the server during denial of service (DoS) attacks. When a large amount of xml is sent to your IIS server as part of the POST data, such as in the TEXTAREA of the asp form, you may get unexpected results. When data is processed on the server, you may encounter errors due to different data processing methods. The reason is that when you submit data back to the server, there is a (data) size limit in the POST field. This aims to prevent possible intruders from sending large amounts of data to the server during denial of service (DoS) attacks.


This restriction also limits your capabilities. But there is a way to solve this problem. If you are not limited to sending data only through FORM submission, 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);


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

Dim oDOMSet oDOM = Server.CreateObject("MSXML2.DOMDocument")oDOM.load Request


If you can only use FORM to submit, you can submit multiple TEXTAREA or INPUT to cross this restriction, when the server receives the FORM data, the preceding two can be combined again:

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);}


This code creates a new FORM element to process data submission and place it in the BODY element. Then, it checks the XML length to be submitted to the server. This XML resides in a TEXTAREA called txtXML in someForm.

If the XML is more than 90,000 characters in MAXLEN, this code creates multiple hidden INPUT elements and sets the value attribute to 90,000 characters in XML data, or set it to a value at the end of the XML to split the data into multiple parts. If the XML size is smaller than MAXLEN, this code creates only one INPUT and sets the value accordingly. Then the data is submitted to the server for processing.

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

Dim str, fldFor Each fld In Request.Form("txtXML")    str = str & fldNext


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

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

If you are looking for a large data solution, such as transferring a large amount of Excel data from the client machine to the server, you should reconsider whether to use FORM for submission, or logically divide the data into several small parts. Since you cannot use an INPUT element of the file type, 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 will be stored on the server until further processing is required.

Of course, there may be a better way to solve this problem. But when you don't have much time, all you need is a fast and available solution.

The above is a detailed description of how to use XMLHTTP to send ultra-long XML form data. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.