转换成UTF-8在传统的ASP ISO-8859-1 [英] convert utf-8 to iso-8859-1 in classic asp

查看:319
本文介绍了转换成UTF-8在传统的ASP ISO-8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站现在工作纯粹是UTF-8,但为了使用ServerXMLHttp我需要我的消息从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.

的情况是平行于这样的:

The situation is parallel to this:

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

and then 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连接codeS响应;

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


  • 什么是EN $ C $光盘作为( UTF-8 的Windows 1252的物理文件(b.asp)西欧(ISO)等)。只要处理codePAGE ASP文件这不应该是一个问题相匹配(我个人preFER使用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).

什么codePAGE不ASP页想到要处理的? (&LT;%@ codePAGE%GT; 属性)

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

您可以用code片段下方测试页摸出你的服务器的默认值是什么;

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

这篇关于转换成UTF-8在传统的ASP ISO-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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