PC-*_*ram 2 ado serverxmlhttp character-encoding asp-classic
我的网站现在纯粹以UTF-8工作,但为了使用serverXMLHTTP发送短信,我需要在发送之前将我的消息从UTF-8转换为ISO-8859-1.
情况与此并行:
a.asp:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body>
<form method="post" action="b.asp">
<input type text name="message" value="æøå and ÆØÅ"><br>
<input type=submit>
</body>
Run Code Online (Sandbox Code Playgroud)
然后是b.asp
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head><body>
<%=konvert(request("message"))%><br>
</body>
<%
Function Konvert(sIn)
Dim oIn : Set oIn = CreateObject("ADODB.Stream")
oIn.Open
oIn.CharSet = "UTF-8"
oIn.WriteText sIn
oIn.Position = 0
oIn.CharSet = "ISO-8859-1"
Konvert = oIn.ReadText
oIn.Close
End Function
%>
Run Code Online (Sandbox Code Playgroud)
在这个展示中,我希望在b.asp中看到相同的字符串,因为我发送了一个a.asp,但是我得到了这个:
æøå and ÆØÅ
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
您处理客户端编码但不处理服务器端
这实际上取决于您的服务器配置,以了解ASP如何处理服务器请求.
处理IIS如何编码响应有两个部分;
什么编码为(物理文件(b.asp)为UTF-8,Windows-1252,Western European (ISO)等).只要处理CodePage与ASP文件匹配,这应该不是问题(我个人更喜欢使用UTF-8,而在较新的IIS版本中这是默认值).
ASP页面期望处理的CodePage是什么?(<%@ CodePage %>属性)
您可以在测试页面中使用下面的代码段来确定您的服务器默认值;
<%
'Check how the server is currently encoding responses.
Call Response.Write(Response.Charset)
Call Response.Write(Response.CodePage)
%>
Run Code Online (Sandbox Code Playgroud)
为了使下面的示例正常工作,b.asp将必须保存为65001(UTF-8),如果您使用的是Visual Studio,则可以使用"高级保存选项"对话框进行操作(默认情况下菜单上未显示)使用"自定义菜单"选项添加).
<%@Language="VBScript" CodePage = 65001 %>
<%
'IIS should process this page as 65001 (UTF-8), responses should be
'treated as 28591 (ISO-8859-1).
Response.CharSet = "ISO-8859-1"
Response.CodePage = 28591
%>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25958 次 |
| 最近记录: |