实现Form表单域中Post大于100K的数据

来源:互联网 发布:外教口语网络培训 编辑:程序博客网 时间:2024/05/19 11:20

在工作中遇到一个问题,当表单发送的数据量很大时,就会报错。查阅MSDN了解到,原因是微软对用Request.Form()可接收的最大数据有限制,IIS4中为80K字节,IIS5中为100K字节,目前还不清楚iis6.0有没有这样的限制或者限制是多少K。

下面是微软提供的几个解决方法:

1、用Request.BinaryRead 代替 Request.Form方法 来解析表单数据;
Request.BinaryRead()读取表单数据,但由于这种方法读出的是二进制数据,需要对读出的数据逐字节进行分析,生成有意义的字符串(MSDN上的一段程序就是这样写的),但是用来解析汉字可能就不是那么简单了


2、使用文件上传方案,比如:Microsoft Posting Acceptor;
这个方法没有用过
3、由于102399字节的限制是对每个表单元素的,所以在提交时,把表单元素内容大于102399的分隔成多个表单元素来提交。

  下面为示例代码:(微软提醒:下面代码不一定完全适用特定的需要,不对使用这些代码产生的后果负责!)

<FORM method=post action=LargePost.asp name=theForm onsubmit="BreakItUp()">
<Textarea rows=3 cols=100 name=BigTextArea>A bunch of text...</Textarea>
<input type=submit value=go>
</form>
<SCRIPT Language=JavaScript>
function BreakItUp()
{
  //Set the limit for field size.
  //如果内容有中文的字符的话,可以设置为:51100
  var FormLimit = 102399
  //Get the value of the large input object.
  var TempVar = new String
  TempVar = document.theForm.BigTextArea.value
  //If the length of the object is greater than the limit, break it
  //into multiple objects.
  if (TempVar.length > FormLimit)
  {
    document.theForm.BigTextArea.value = TempVar.substr(0, FormLimit)
    TempVar = TempVar.substr(FormLimit)
    while (TempVar.length > 0)
    {
      var objTEXTAREA = document.createElement("TEXTAREA")
      objTEXTAREA.name = "BigTextArea"
      objTEXTAREA.value = TempVar.substr(0, FormLimit)
      document.theForm.appendChild(objTEXTAREA)
     
      TempVar = TempVar.substr(FormLimit)
    }
  }
}
</SCRIPT>
     
接受数据页主要代码:

<%
Dim BigTextArea
For I = 1 To Request.Form("BigTextArea").Count
  BigTextArea = BigTextArea & Request.Form("BigTextArea")(I)
Next
%>

注意:限制的不是整个表单数据的总和不能超过100KB,而是对表单内每个域的限制不能超过100KB

 

原创粉丝点击