【问题标题】:Classic ASP: Emit Response with charset UTF-16经典 ASP:使用字符集 UTF-16 发出响应
【发布时间】:2016-09-16 15:06:49
【问题描述】:

我需要在经典 ASP 中编写一个脚本来生成一个 CSV 文件供用户下载。它需要以“经典的 Windows Unicode”编码,即 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?

【问题讨论】:

  • 您似乎很清楚,所以这可能不相关,但我认为您无法让 ASP 支持 UTF-16(请参阅this answer 的更新)。很抱歉成为坏消息的承担者。
  • @Lankymart 谢谢,太糟糕了。您认为可以使用流和 Response.BinaryWrite 或类似的东西来实现它吗?
  • 老实说@angus,在.Net 之类的东西中编写一个COM 组件来执行它然后从ASP 调用它或者尝试获得接受UTF-8 的要求会更容易。祝你好运,很抱歉这没有多大帮助。

标签: character-encoding asp-classic httpresponse utf-16 codepages


【解决方案1】:

好吧,我使用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 来存储文本这一事实。

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2010-10-29
    相关资源
    最近更新 更多