I encountered a problem at work before. When the amount of data sent by the form was large, an error would be reported. Checking MSDN, we learned that the reason is that Microsoft limits the maximum data that can be received using Request.Form() to 100K bytes. Microsoft recommends using Request.BinaryRead() to read form data, but since this method reads binary data, the read data needs to be analyzed byte by byte to generate a meaningful string (a program on MSDN is is written this way, but it does not take into account that escaped characters such as punctuation require special analysis). If this method is barely usable for pure English systems, it will be very troublesome for Chinese systems, because Chinese characters are represented by two bytes, and the read binary data itself cannot determine whether it is English or English. Chinese characters (otherwise it would not be binary data, but a string ^-^). In this case, you must understand the encoding rules of Chinese characters in order to perform analysis. Finally, even if the algorithm can analyze all these, think about how efficient it is to analyze a MB-level giant string byte by byte? Therefore, this road is blocked!
However, there is always a way. At first I thought it was that the total form data could not exceed 100KB, but later I found out that this was a limit for each field in the form. The solution to the problem is that for a domain that needs to send big data, split the data into several parts smaller than the limit before submitting the form, place them in several hidden fields, clear the original fields at the same time, and then formally submit the form. . The server still uses Request.Form() to read the data in each hidden field, and then splice them together in order. The main code is as follows:
Note: You need to specify a DIV within the HTML code in the Form to dynamically insert the hidden field into it.
====Client sample code====
Copy the code code as follows:
<SCRIPT language=javascript>
//The data is split and placed in the corresponding hidden domain, which is triggered in the onSubmit event of the Form
function fnPreHandle()
{
var iCount; //How many domains to split into
var strData; //original data
var iMaxChars = 50000;//Considering that Chinese characters are double bytes, the maximum number of characters in the domain is limited to 50K
var iBottleNeck = 2000000; //If the article exceeds 2M words, the user needs to be prompted
var strHTML;//original data
strData = frmTest.BigField.value;//If the article is too long, the user needs to be reminded
if (strData.length > iBottleNeck)
{
if (confirm(The article you want to publish is too long, it is recommended that you split it into several parts and publish them separately./nIf you insist on submitting, please note that it will take a long time to submit successfully./n/nDo you insist on submitting?) == false )
return false;
}iCount = parseInt(strData.length / iMaxChars) + 1;//hdnCount records how many subfields the original data field is split into
strHTML = <input type=hidden name=hdnCount value= + iCount + >;//Generate HTML code for each subdomain
for (var i = 1; i <= iCount; i++)
{
strHTML = strHTML + /n + <input type=hidden name=hdnBigField + i + >;
}//Dynamicly insert the HTML code of each hidden domain into the DIV (divHidden) in the Form
document.all.divHidden.innerHTML = strHTML;//Assign values to each subdomain
for (var i = 1; i <= iCount; i++)
{
frmTest.elements[hdnBigField + i].value = strData.substring((i - 1) * iMaxChars, i * iMaxChars);
}//Clear the original data field
frmTest.BigField.value = ;
}
</SCRIPT>
====Server-side sample code====
Copy the code code as follows:
<%
Dim strData
Dim intFieldCount
Dim iintFieldCount = Request.Form(hdnCount)For i=1 To intFieldCount
strData = strData & Request.Form(hdnBigfield & i)
NextResponse.Write strData
%>