How do I post more than 100K bytes of data in the form field?

Source: Internet
Author: User
Tags split
How data can post more than 100K bytes in the form field????


Previously encountered a problem in the work, when the form sent a large amount of data, it will be an error. Check out MSDN to learn that Microsoft is limited to 100K bytes for the maximum data that can be received with Request.Form ().

Microsoft recommends using Request.BinaryRead () to read form data, but because this method reads binary data, it needs to parse the read out bytes, generating a meaningful string (a program on MSDN is written like this, However, it does not take into account the need for special analysis of escape characters such as punctuation. If this approach is barely available for a pure English system, for the Chinese system has great trouble, because the Chinese character is expressed in two bytes, and read the binary data itself can not be judged in English or Chinese characters (otherwise it is not binary data, but the string of ^). In this way, we must understand the coding rules of Chinese characters in order to analyze. Finally, even if the algorithm can analyze all of these, we think of a MB-level mega-string analysis by Byte, how efficient? So, blocked!

But there is always a way. At first I thought it was the sum of the form's data cannot exceed 100KB, which was later found to be a restriction on each field within the form. The solution to the problem is that, for a domain that needs to send large data, the data is split into a number of smaller than the limit before submitting the form, placed in several hidden fields, and emptied of the original field, then formally submits the form. Server-side or with Request.Form () read the data of each hidden field, and then in order to put them together on the line. 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 = = =
<script language=javascript>
The data is split and placed in the corresponding hidden field, which fires in the form's onsubmit event
function Fnprehandle ()
{
var icount; How many fields are split into
var strdata; Raw data
var imaxchars = 50000;//The maximum number of characters in a field is limited to 50K, taking into account that Chinese characters are double-byte
var Ibottleneck = 2000000;//If the article is more than 2M words, you need to prompt the user
var strhtml;

Raw data
Strdata = FrmTest.BigField.value;

If the article is really too long, you need to remind the user
if (Strdata.length > Ibottleneck)
{
If confirm ("the article you are publishing is too long, it is recommended that you split it into several sections and publish separately.") \ NAND If you insist on submitting, note that it will take a long time to commit successfully. \ n \ ndo you insist on submitting? ") = = False)
return false;
}

icount = parseint (strdata.length/imaxchars) + 1;

Hdncount record the number of subdomains that the original data field is split into
strhtml = "<input type=hidden name=hdncount value=" + icount + ">";

Generate HTML code for each child domain
for (var i = 1; I <= icount; i++)
{
strHTML = strhtml + "\ n" + "<input type=hidden Name=hdnbigfield" + i + ">";
}

Dynamically insert HTML code for each hidden field within div (Divhidden) in form
Document.all.divHidden.innerHTML = strhtml;

Assigning values to each subdomain
for (var i = 1; I <= icount; i++)
{
frmtest.elements["Hdnbigfield" + I].value = strdata.substring ((i-1) * Imaxchars, I * imaxchars);
}

Empty the original data field
FrmTest.BigField.value = "";
}
</script>

= = = = = Server-side Sample Code = =
<%
Dim strdata
Dim Intfieldcount
Dim I

Intfieldcount = Request.Form ("Hdncount")

For I=1 to Intfieldcount
strdata = strdata & Request.Form ("Hdnbigfield" & i)
Next

Response.Write Strdata
%>


Why do you think Microsoft has to have a 100KB limit? Hun!



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.