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

Mar 04, 2017 pm 05:24 PM

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:

1

2

3

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:

1

2

3

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:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

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:

1

2

3

4

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)!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

HTTP 200 OK: Understand the meaning and purpose of a successful response HTTP 200 OK: Understand the meaning and purpose of a successful response Dec 26, 2023 am 10:25 AM

HTTP Status Code 200: Explore the Meaning and Purpose of Successful Responses HTTP status codes are numeric codes used to indicate the status of a server's response. Among them, status code 200 indicates that the request has been successfully processed by the server. This article will explore the specific meaning and use of HTTP status code 200. First, let us understand the classification of HTTP status codes. Status codes are divided into five categories, namely 1xx, 2xx, 3xx, 4xx and 5xx. Among them, 2xx indicates a successful response. And 200 is the most common status code in 2xx

http request 415 error solution http request 415 error solution Nov 14, 2023 am 10:49 AM

Solution: 1. Check the Content-Type in the request header; 2. Check the data format in the request body; 3. Use the appropriate encoding format; 4. Use the appropriate request method; 5. Check the server-side support.

How to use PHP functions to process XML data? How to use PHP functions to process XML data? May 05, 2024 am 09:15 AM

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

What status code is returned for an HTTP request timeout? What status code is returned for an HTTP request timeout? Feb 18, 2024 pm 01:58 PM

The HTTP request times out, and the server often returns the 504GatewayTimeout status code. This status code indicates that when the server executes a request, it still fails to obtain the resources required for the request or complete the processing of the request after a period of time. It is a status code of the 5xx series, which indicates that the server has encountered a temporary problem or overload, resulting in the inability to correctly handle the client's request. In the HTTP protocol, various status codes have specific meanings and uses, and the 504 status code is used to indicate request timeout issues. in customer

See all articles