的multipart / form-data的和UTF-8的ASP应用经典 [英] Multipart/form-data and UTF-8 in a ASP Classic application

查看:350
本文介绍了的multipart / form-data的和UTF-8的ASP应用经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我真的不明白的一个问题。
我想在ASP经典的应用程序上传文件,无需使用外部组件。我也想张贴将被存储在一个数据库一些文本。
文件上传完美,我用这code:的上传文件,没有刘易斯E. MOTEN III COM V3

I have a problem that I really don't understand. I'm trying to upload a files in a asp classic app, without the use of an external component. I also want to post some text that will be stored in a DB. The file upload perfectly, I'm using this code: Upload Files Without COM v3 by Lewis E. Moten III

的问题是其它形式的输入字段。我使用的是UTF-8,但他们最终不会为UTF-8。如果我把它们打印出来使用的Response.Write即瑞典字符的A型和O被​​显示为questinmarks。

The problem is the other form input fields. I'm using UTF-8, but they don't end up as UTF-8. I.e Swedish characters å ä and ö is displayed as questinmarks if I print them out using Response.Write.

我在UTF-8(带BOM)保存的文件,我已经添加了元标记告诉页面它是UTF-8。我已经设置Response.Charset的=UTF-8。

I have saved the files in UTF-8 (with BOM), I have added the meta tag to tell the page it is in UTF-8. I have set Response.CharSet = "UTF-8".

该函数从二进制转换成字符串看起来像这样(这是我能想到的可能是错误的,因为评论说,它拉ANSI字符的唯一地方,但我认为它应该拉的Uni code字符):

The function to convert from binary to string looks like this (this is the only place I can think of that might be wrong, since the comments say that it pulls ANSI characters, but I think it should pull Unicode characters):

Private Function CStrU(ByRef pstrANSI)

    ' Converts an ANSI string to Unicode
    ' Best used for small strings

    Dim llngLength ' Length of ANSI string
    Dim llngIndex ' Current position

    ' determine length
    llngLength = LenB(pstrANSI)

    ' Loop through each character
    For llngIndex = 1 To llngLength

        ' Pull out ANSI character
        ' Get Ascii value of ANSI character
        ' Get Unicode Character from Ascii
        ' Append character to results
        CStrU = CStrU & Chr(AscB(MidB(pstrANSI, llngIndex, 1)))

    Next

End Function

我创建了一个测试ASP页(multiparttest.asp)复制此,需要从刘易斯E. MOTEN上传的东西,使其工作(我加了他的文件放在一个子目录称为上传)。

I have created a test asp page (multiparttest.asp) to replicate this, the upload stuff from Lewis E. Moten is required to make it work (I have added his files in a subdir called upload).

<%Response.CharSet = "UTF-8" %>
<!--#INCLUDE FILE="upload/clsUpload.asp"-->
<html>
    <head>
        <title>Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <%
        Set objUpload = New clsUpload
        Response.Write( objUpload.Fields("testInput").Value )
        %>
        <form method="post" enctype="multipart/form-data" action="multiparttest.asp">
            <input type="text" name="testInput" />
            <input type="submit" value="submit" />
        </form>

    </body>
</html>

我已抓获使用LiveHTTP头在Firefox的请求,并将它保存为UTF-8的文件,瑞典人物看起来像他们应该(他们没有看在LiveHTTP头GUI不错,但我猜测, GUI而言,自不使用正确的编码)。这是POST请求的样子:

I have captured the request using LiveHTTP Headers in Firefox, and saved it as a UTF-8 file, the Swedish characters looks like they should (they didn't look ok in the LiveHTTP header GUI, but i'm guessing that the GUI it self doesn't use the correct encoding). This is how the POST request looks like:

http://localhost/testsite/multiparttest.asp

POST /testsite/multiparttest.asp HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/testsite/multiparttest.asp
Cookie: ASPSESSIONIDASBBRBTT=GLDJDBJALAMJFBFBDCCIONHF; ASPSESSIONIDAQABQBTT=DIPHILKAIICKJOIAIMILAMGE; ASPSESSIONIDCSABTCQS=KMHBLBLABKHCBGPNLMCIPPNJ
Content-Type: multipart/form-data; boundary=---------------------------7391102023625
Content-Length: 150
-----------------------------7391102023625
Content-Disposition: form-data; name="testInput"

åäö
-----------------------------7391102023625--

HTTP/1.x 200 OK
Cache-Control: private
Content-Length: 548
Content-Type: text/html; Charset=UTF-8
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Tue, 10 Nov 2009 14:20:17 GMT
----------------------------------------------------------

在此母校任何帮助是AP preciated!

Any help in this mater is appreciated!

我试过所有这些添加到ASP文件的顶部,由于不同的建议,我对这个问题的其他洁具发现,没有不同的结果。

I've tried to add all these to the top of the asp file, due to different suggestions I've found on this problem else ware, with no different result..

<%@Language=VBScript codepage=65001 %>
<%Response.ContentType="text/html"%>
<%Response.Charset="UTF-8"%>
<%Session.CodePage=65001%>

编辑11/11:

此问题似乎有关,<一个href=\"http://stackoverflow.com/questions/546365/utf-8-text-is-garbled-when-form-is-posted-as-multipart-form-data\">UTF-8当窗体作为多/ form-data的文字是乱码。但他们不使用ASP或IIS。是否有可能建立某种形式的字符编码​​为IIS中的multipart / form-data的吗?我使用的IIS7。也许我的要求确实有后,所有的错误编码? (我真的失去了在字符编码世界现在)

EDIT 11/11:

This question seems related, UTF-8 text is garbled when form is posted as multipart/form-data. But they doesn't use ASP or IIS. Is it possible to setup some kind of character encoding for multipart/form-data in IIS? I'm using IIS7. Maybe my request does have the wrong encoding after all? (I'm really lost in the character encoding world right now)

推荐答案

您CStrU的分析是正确的。它假定单字节ANSI字符正在由客户端发送。它还假定正在使用的客户端和语言环境VBScript的运行中是相同的codePAGE。

Your analysis of CStrU is correct. It assumes that single byte ANSI characters are being sent by the client. It also assumes that the codepage being used by both client and locale that the VBScript is running in are the same.

在使用UTF-8 CStrU作出的假设永远是不正确的。没有,据我所知,有65001为codePAGE一个区域(我觉得有使用65000一两个但那又有所不同)。

When using UTF-8 the assumptions made by CStrU will always be incorrect. There isn't, to my knowledge, a locale that has 65001 as its codepage (I think there are one or two that use 65000 but thats different again).

下面是假定文本替换功能是UTF-8: -

Here is a replacement function that assumes text is in UTF-8:-

 Private Function CStrU(ByRef pstrANSI)

  Dim llngLength '' # Length of ANSI string
  Dim llngIndex '' # Current position
  Dim bytVal
  Dim intChar

  '' # determine length
  llngLength = LenB(pstrANSI)

  '' # Loop through each character
  llngIndex = 1
  Do While llngIndex <= llngLength

   bytVal = AscB(MidB(pstrANSI, llngIndex, 1))
   llngIndex = llngIndex + 1

   If bytVal < &h80 Then
    intChar = bytVal
   ElseIf bytVal < &hE0 Then

    intChar = (bytVal And &h1F) * &h40

    bytVal =  AscB(MidB(pstrANSI, llngIndex, 1))
    llngIndex = llngIndex + 1

    intChar = intChar + (bytVal And &h3f)

   ElseIf bytVal < &hF0 Then

    intChar = (bytVal And &hF) * &h1000

    bytVal =  AscB(MidB(pstrANSI, llngIndex, 1))
    llngIndex = llngIndex + 1

    intChar = intChar + (bytVal And &h3F) * &h40

    bytVal =  AscB(MidB(pstrANSI, llngIndex, 1))
    llngIndex = llngIndex + 1

    intChar = intChar + (bytVal And &h3F)

   Else
    intChar = &hBF
   End If

   CStrU = CStrU & ChrW(intChar)
  Loop

 End Function

请注意,与CStrU正在为UTF-8纠正您的示例页面的输出现在看起来是错误的。到该文件的codePAGE设置为65001的建议也是一个要求。既然你设置字符集发送到客户端为UTF-8你还需要告诉ASP编码使用的Response.Write文本写入时使用UTF-8 code页面。

Note that with CStrU being corrected for UTF-8 the output of your example page now looks wrong. The advice to set the Codepage of the file to 65001 is also a requirement. Since you are setting the CharSet sent to the client to "UTF-8" you need to also tell ASP to use the UTF-8 code page when encoding text written using Response.Write.

这篇关于的multipart / form-data的和UTF-8的ASP应用经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆