Re: Firefox 3 beta 5 - when sending XMLHTTPRequest, content-type request header is forced to ISO-8859-1 encoding instead of UTF-8

Boris Zbarsky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
[email protected] wrote:
> In my test example, I attempt to explicitly set the content-type
> header to "text/xml;charset=utf-8", as well as verify that the
> xmlEncoding is null.

First of all, the documentation doesn't seem to be correct.  Firefox will use 
the encoding of the Document you pass to send().  If the document doesn't have 
an XML prolog, its xmlEncoding will always be null, whereas the encoding of the 
document may well not be.  What XMLHttpRequest is actually using in DOM terms is 
the non-standard document.characterSet.

In your example, you create a document via createDocument().  Sadly, there is no 
way to specify the encoding to use for such documents, and it defaults to 
ISO-8859-1.

> However, when I view the request headers in FF3 I see:
> Content-Type    text/xml; charset=ISO-8859-1

Right.  That's the change: the actual encoding of the document is now used no 
matter what the page claims it's encoded as....

> and the content on the server side is garbled

Only if you decode it as UTF-8 without paying attention to what the data 
actually is, right?

> Does anyone have any idea on how to control this? Or how to set the
> xmlEncoding property if necessary? Or what I'm doing wrong ;) ?

I don't think you can change the encoding of an existing Document object.  You 
can create a document with an arbitrary encoding by using DOMParser on a string 
with the proper XML prolog, I would think.

-Boris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.