经典ASP:使用字符集UTF-16发送响应
问题描述:
我需要在经典ASP中执行脚本以生成供用户下载的CSV文件。它需要用“经典的Windows Unicode”编码,即UTF-16。经典ASP:使用字符集UTF-16发送响应
我尝试这样做:
Response.Clear
Response.ContentType = "text/csv"
Response.Charset = "utf-16"
Response.Codepage = 1200
Response.AddHeader "Content-Disposition", "attachment; filename=export.csv"
,但我得到的错误
错误-2147467259:〜指定了无效的代码页值006〜ASP 0204〜无效的代码页值。
这很有意义,因为根据文档,代码页1200仅适用于托管(ASP.NET)应用程序。
但是,那么如何设置响应的字符集为UTF-16?
答
那么,我使用ADODB.Stream
“解决”它。这样做的缺点是我需要在将内容发送给用户之前在内存中累积完整的输出。基本上,
dim s
set s = Server.CreateObject("ADODB.Stream")
s.Type = 2 ' text '
s.Open
do while <getting data>
s.WriteText <data>
loop
s.Flush
s.Position = 1
s.Type = 1 ' binary '
Response.Clear
Response.ContentType = "application/csv"
Response.AddHeader "Content-Disposition", "attachment; filename=export.csv"
Response.BinaryWrite s.Read
这使用的事实,ADODB.Stream
默认情况下使用Unicode来存储文本。
你似乎找到了线索,所以这可能不相关,但我不认为你可以得到ASP来支持UTF-16(请参阅本答案的更新(http://*.com/a/25646123/692942 ))。对不起,成为坏消息的持有者。 – Lankymart
@Lankymart谢谢,这太糟糕了。你认为可以使用流和Response.BinaryWrite或类似的东西来实现它吗? – angus
说实话@angus可以更容易地写一个COM组件来做类似于.Net的事情,然后从ASP调用它,或者尝试获取接受UTF-8的需求。祝你好运,对不起,没有太大的帮助。 – Lankymart