4

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>

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

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 ÆØÅ

Any ideas?

PC-Gram
  • 81
  • 1
  • 2
  • 11

1 Answers1

7

Your handling the client side encoding but not the server side

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

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

  • 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).

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

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
%>
user692942
  • 16,398
  • 7
  • 76
  • 175
  • You are probaly right, however in my real world problem, b.asp represents the SMS provider and I have no idea about how his part. Only that he must receive the message encoded as ISO-8859-1. Meanwhile I have worked out a small snippet (see below) that might solve my problem. – PC-Gram Jul 16 '13 at 16:13
  • I assumed b.asp was a middleman between your message and the sms sending mechanism. You could still use that approach to let the server convert the UTF-8 encoding to ISO-8859-1 for you then send to your SMS provider using ServerXmlHttp. – user692942 Jul 16 '13 at 17:09
  • Case closed: I added the two lines ...charset="ISO-8859.1" and ...codepage=28591 immediately before sending data and then immediately after restored to "UTF-8" and 65001 in order for my UTF-8 based pages to render some special characters correctly correctly – PC-Gram Jul 16 '13 at 20:55
  • ASP seems to be able to parse 65001 without specifying it in the declaration. – Ian Warburton Dec 12 '15 at 16:54
  • @IanWarburton Yes it can, but it means you make a lot of assumptions, I'm trying to help people understand the problem. – user692942 Dec 12 '15 at 18:44