當(dāng)前位置:首頁文章首頁 IT學(xué)院 IT技術(shù)

關(guān)于ASP中大字段在Form中Post出錯(cuò)的解析

作者:  來源:  發(fā)布時(shí)間:2011-6-28 11:35:38  點(diǎn)擊:

這篇文章將會(huì)介紹到關(guān)于ASP中大字段在Form中Post出錯(cuò)的解析,希望對(duì)大家能夠有幫助。

我們?cè)谑褂煤芏嘈侣勏到y(tǒng)的時(shí)候,都會(huì)發(fā)現(xiàn)一個(gè)問題,尤其是使用 HtmlEdit 從WORD文檔中直接拷貝文章(尤其里面有復(fù)雜表格和文字)的時(shí)候,提交會(huì)有一個(gè)錯(cuò)誤發(fā)生。

"Request Object, ASP 0107 (0x80004005)"

很多編程人員都以為是 Access 數(shù)據(jù)庫備注字段64kb限制的問題,開始 icech 也以為是,但是后來用了其他新聞系統(tǒng)的 SQL 版本,同樣的問題發(fā)生了。因此我猜想,可能是瀏覽器的問題。但是 Form 表單使用的都是 Post 方式,應(yīng)該和瀏覽器無關(guān),那是什么原因呢?

程序出錯(cuò)提示總是在 Request.Form(“xxx”)的地方,因此我判斷,可能是Request有大小的限制。然后就去MSDN上查找“ASP 0107 (0x80004005)”,果然是Request的問題。微軟的原文是這樣的。

PRB: Error "Request Object, ASP 0107 (0x80004005)" When You Post a Form

The information in this article applies t

Microsoft Active Server Pages

This article was previously published under Q273482

SYMPTOMS

When you post a large form field in Microsoft Internet Information Services 5.0, you may receive the following error message:

Error Type:

Request object, ASP 0107 (0x80004005)

The data being processed is over the allowed limit.

When you post a large form field in Microsoft Internet Information Server 4.0, you may receive the following error message:

Request object error 'ASP 0107 : 80004005'

Stack Overflow

/projectname/page.asp, line XX

The data being processed is over the allowed limit.

CAUSE

The size limit of each form field that is retrieved in the Request object is 102,399 bytes. The error occurs when you exceed this limit.

RESOLUTION

To resolve this problem, use one of the following methods:

Instead of reading form variable values with the Request.Form collection, use Request.BinaryRead (Request.TotalBytes), and parse the form values from the output of Request.BinaryRead.

Use a File Upload scheme, such as Microsoft Posting Acceptor.

Break the HTML form variables into multiple form variables before you submit the form. The 102,399 byte limit is for each form variable, so you can have multiple form variables of 102,399 characters or less. The following sample code illustrates this: WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

<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=java script>

function BreakItUp()

{

//Set the limit for field size.

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>

The receiving Active Server Page (ASP) page reconstructs the variable:

<%

Dim BigTextArea

For I = 1 To Request.Form("BigTextArea").Count

BigTextArea = BigTextArea & Request.Form("BigTextArea")(I)

Next

%>

100 K的限制?微軟竟然來這一手!幸好他們自己給出了幾個(gè)解決方案,看一下上文可以知道,微軟提供了2種可行的方法:

第一種使用Request.BinaryRead (Request.TotalBytes),第二種使用分段上傳的方式,基于少更改程序的原則,我們采用第二種方式。但是在使用的過程中,icech無意中發(fā)現(xiàn),直接使用

For I = 1 To Request.Form("BigTextArea").Count

BigTextArea = BigTextArea & Request.Form("BigTextArea")(I)

Next

來代替Request.Form("BigTextArea")竟然也能達(dá)到同樣的效果!驚奇!我想可能系統(tǒng)每次將100K的內(nèi)容發(fā)送給Request,上段程序又在進(jìn)行循環(huán),因此達(dá)到了同樣的效果。

以上是icech解決問題的方法,現(xiàn)在新聞系統(tǒng)例如:?jiǎn)炭、?dòng)力、惠信比較好的系統(tǒng)也都存在這個(gè)問題,大家可以試著用這種方法來解決。

下面再給大家提供一個(gè)我在CSDN上發(fā)現(xiàn)的一個(gè)帖子,和我寫的異曲同工,解決了一樣的問題,方法也一樣,供參考:

如何在Form域中Post大于100K字節(jié)的數(shù)據(jù)????

以前在工作中遇到一個(gè)問題,當(dāng)表單發(fā)送的數(shù)據(jù)量很大時(shí),就會(huì)報(bào)錯(cuò)。查閱MSDN了解到,原因是微軟對(duì)用Request.Form()可接收的最大數(shù)據(jù)限制為100K字節(jié)。

微軟建議用Request.BinaryRead()讀取表單數(shù)據(jù),但由于這種方法讀出的是二進(jìn)制數(shù)據(jù),需要對(duì)讀出的數(shù)據(jù)逐字節(jié)進(jìn)行分析,生成有意義的字符串(MSDN上的一段程序就是這樣寫的,但它并沒有考慮諸如標(biāo)點(diǎn)符號(hào)等轉(zhuǎn)義字符需要進(jìn)行特殊分析)。如果說這種方法對(duì)于純英文系統(tǒng)勉強(qiáng)可用的話,則對(duì)于中文系統(tǒng)來說就有極大的麻煩,因?yàn)闈h字是用兩個(gè)字節(jié)表示的,而讀出的二進(jìn)制數(shù)據(jù)本身并不能判斷是英文還是漢字(否則就不是二進(jìn)制數(shù)據(jù),而是字符串了^-^)。

相關(guān)軟件

相關(guān)文章

文章評(píng)論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z