Question

I have created a small test page using Sencha Touch, OpenLayers and I am recieving WMS/WFS data from a GeoServer.

I have set the encoding on my HTML page to UTF-8:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I pull some WFS data from my GeoServer using the following statement:

var post = new OpenLayers.Request.POST({
    url: 'dataprovider.ashx',
    data: ...,
    headers: {
        "Content-Type": "text/xml;charset=utf-8"
    },
    callback: function (response) {
        ...
    },
});

Which I believe should give me the requested data encoded as UTF-8.

Using an IPhone 4 (IOS 4) and a Samsung Galaxy Tab 10.1 (Android 3.1) it works just fine.

My problem is: Using a device with Android 2.2, I get data back in a different encoding.

One of the words I expect to recieve is Høj, but I recieve Høj (ANSI).

Using FireFox and Chrome I know how to debug the response from the GeoServer, but I don't know how to debug the phones or tablets.

Why is the encoding wrong on Android 2.2?

UPDATED: The problem seems to be related to devices using Android 2.2. A HTC Legend, a Samsung Galaxy SII and a Samsung Galaxy Tab 7 is having the problem - all running Android 2.2.

Was it helpful?

Solution

I have faced exactly the same problem using GeoServer, openLayers, and Android browser (Android 2.2).

I made some research looking for place where the problem exist. All in all I went down to XMLHttpRequest.js. In this file openLayers is creating XMLHttpRequest object making request and receiving response. I have found also that in this stage already received data has encoding problem.

I have also sniffed communication using wireshark to assure that data I am sending is in correct encoding (utf-8). I dumped this data and figured out that it was correct utf-8 data. But what was interesting that when I tried display my utf-8 data using iso-8859-1 I received exactly the same output as in Android browser.

My conclusion: In android 2.2 web browser XMLHttpRequest object is always reading data assuming iso-8859-1 encoding.

My solution: You have to fix string yourself. First you have to made map where you have to memorize that for instance "ø" is "ø". And then by examining character by character when you find "ø" sequence substitute it by "ø". This is example code:

goodString = "";
for( i = 0; i < wrongString.length; i++) {
    var w = wrongString.charCodeAt(i);
    var c = wrongString.charAt(i);
    if(w == "Ã".charCodeAt(0) {
        w2 = wrongString.charCodeAt(++i);
        if(w2 == "¸".charCodeAt(0))
            c = 'ø';
    }
    goodString += c;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top