在经典asp中将utf-8转换为iso-8859-1 [英] convert utf-8 to iso-8859-1 in classic asp

查看:36
本文介绍了在经典asp中将utf-8转换为iso-8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站现在完全使用 UTF-8,但为了使用 serverXMLHTTP 发送 SMS,我需要在发送之前将我的消息从 UTF-8 转换为 ISO-8859-1.

My site now works purely in UTF-8, but in order to send an SMS using serverXMLHTTP I need to convert my message from UTF-8 til ISO-8859-1 before sending it.

情况与此类似:

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>

然后是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
%>

在这个展示中,我希望在 b.asp 中看到与我发送 a.asp 相同的字符串但我得到的是这个:

In this showcase I would expect to see the same string in b.asp as I send i a.asp but what I get i this:

æøå and ÆØÅ

有什么想法吗?

推荐答案

您处理的是客户端编码而不是服务器端

Your handling the client side encoding but not the server side

关于 ASP 如何处理服务器请求,这实际上取决于您的服务器配置.

It really depends on your server configuration as to how ASP is handling server requests.

处理 IIS 如何编码响应有两个部分;

There are two parts to dealing with how IIS encodes responses;

  • 什么是编码为 (UTF-8Windows-1252西欧 (ISO) 等).只要处理代码页与 ASP 文件匹配,这应该不是问题(我个人更喜欢使用 UTF-8,而在较新的 IIS 版本中,这是默认设置).

  • What is the physical file (b.asp) encoded as (UTF-8, Windows-1252, Western European (ISO) etc). As long as the processing CodePage matches the ASP file this should not be an issue (personally I prefer to use UTF-8 and in newer IIS versions this is the default).

ASP 页面期望被处理为什么 CodePage?(<%@ CodePage %> 属性)

What CodePage does the ASP page expect to be processed as? (<%@ CodePage %> attribute)

您可以在测试页面中使用下面的代码片段来确定您的服务器默认设置是什么;

You can use the code snippet below in a test page to work out what your server defaults are;

<%
'Check how the server is currently encoding responses.

Call Response.Write(Response.Charset)
Call Response.Write(Response.CodePage)
%>

为了让下面的示例正常工作,b.asp 必须保存为 65001 (UTF-8),如果您使用的是 Visual Studio,可以使用高级保存选项"对话框(未显示在菜单上)来完成默认情况下必须使用自定义菜单选项添加).

For the below sample to work correctly b.asp will have to be saved as 65001 (UTF-8), if you're using Visual Studio this can be done using the "Advanced Save Options" dialog (not shown on menu by default has to be added using Customise Menu options).

<%@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
%>

这篇关于在经典asp中将utf-8转换为iso-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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