views:

2251

answers:

13

Hi!

have a problem with classic asp. The encoding gets wrong when I send data with XMLHttp.send. The response is an pdf file, but the “ÆØÅ” gets wrong, the “Ø” is read as “øy” for example. It’s like it’s a converting mistake from UTF-8 to ISO-8859-1, but it should be ISO-8859-1 now. I have <%@CODEPAGE="28591"%> at the top at the page and ISO-8859-1 as encoding in the xml file, I have checked the file so it’s valid ISO-8859-1. I don’t have access to the server I send this data to, but I fixed it in a VB6 program which use the same logic with:

aPostBody = StrConv(strBody, vbFromUnicode)

WinHttpReq.SetTimeouts 100000, 100000, 100000, 1000000

WinHttpReq.Send aPostBody

And in a C# program that also uses the same logic with

// ISO-8859-1

byte[] bytes = Encoding.GetEncoding(28591).GetBytes(data);

But in asp classic I could need some help to find a way to change the encoding on a string to ISO-8859-1…thanks for help!

+2  A: 

Try:

Session.CodePage = 28591

There is some good information here, and I got the CodePage number here.

RedFilter
Thanks, I was looking for a code page list.
lambacck
A: 

Thanks for the answer, I didn't work. I can't really see why not, but since I managed to change it in the two other version I guess there is a way to change it in classic ASP to.

+1  A: 

Have you tried using Response.Charset and setting it like so:

<% Response.Charset="ISO-8859-1"%>

A: 

AFAIK this is a known problem with WinHttpReq / XMLHTTPRequest, hope someone proves me wrong.

dr. evil
A: 

Have you tried using the meta tag equivalent to what you are doing?

Example: Response.Write("")

Note: I use a "response.write" to paste spit out the charset, because Visual Studio will attempt to save the file with a different encoding if, for example, the charset is UTF-8.

A: 

Sorry, my example had HTML but was stripped out.

A: 

Also, please note that the default encoding returned by .NET will be UTF-8. If you want a different encoding type, you can do so in the web.config and/or handle it specifically with code.

A: 

Thanks for the answer! I couldn't get the response.write to work either. The problem is that this part of the solution is made in classic asp, so I don't have the libraries I wish I had from .net. The thing I’m trying to do is send a string to XMLHTTP.Send like this:

XMLHttp.send strBody

The strbody object will look like this:

strBody = "--Xu02=$" & vbCrLf & _ "Content-Disposition: form-data; name=file; filename=" & vbCrLf & _ "Content-type: file" & vbCrLf & vbCrLf & _ strXML & vbCrLf & _ "--Xu02=$--"

and I then get a PDF in return

The variable strXML is the xml I’m sending in, I write this to a file before the send request, so I could verify that it's up to the standard.

A: 

Check the enconding of the .ASP file and all the .ASP file included with #include

Once I have a problem when I create a new .ASP file in VS and was enconding in UTF-8. This file was included by others, and the file enconding "overwrites" all other enconding commands.

Eduardo Molteni
A: 

Eduardo is correct.

However, if that still is not the problem and since you are using XMLhttp.send, why don't you reference http://msdn.microsoft.com/en-us/library/ms763811(VS.85).aspx to set the charset for the request.

A: 

Thanks for all the answers! Nothing seems to work, but I think the problem might be on the server I send it to, I must have tried it all now... I will set up a test server so I can check what happens when I post to that. Thanks for help!

A: 

Hi, I have used this component both on ASP and Javascript, but on javascript I found the resolution for this issue here: http://squio.nl/blog/2006/06/27/xmlhttprequest-and-character-encoding/

bye!