Sencha Touch,OpenLayers,GeoServer:使用Android 2.2的设备上的编码错误 [英] Sencha Touch, OpenLayers, GeoServer: Wrong encoding on devices using Android 2.2

查看:208
本文介绍了Sencha Touch,OpenLayers,GeoServer:使用Android 2.2的设备上的编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用 Sencha Touch OpenLayers 创建了一个小型测试页面,并且正在从GeoServer 接收WMS / WFS数据。



我已将HTML页面上的编码设置为UTF-8:

 < meta http-equiv =Content-Typecontent =text / html; charset = utf-8/> 

我使用以下语句从GeoServer中提取一些WFS数据:

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

我相信应该把请求的数据编码为UTF-8。



使用IPhone 4(IOS 4)和三星Galaxy Tab 10.1(Android 3.1),效果很好。



我的问题是:在Android 2.2中使用设备,我以不同的编码返回数据。



我期望收到的一个字是Høj,但我收到Hø



使用FireFox和Chrome我知道如何调试来自GeoServer的响应,但我不知道如何



p> UPDATED :问题似乎与使用Android 2.2的设备有关。 HTC Legend,Samsung Galaxy SII和Samsung Galaxy Tab 7都有问题 - 所有都运行Android 2.2。

解决方案

我使用GeoServer,openLayers和Android浏览器(Android 2.2)时遇到了完全相同的问题。



我做了一些研究寻找存在问题的地方。总而言之,我去了XMLHttpRequest.js。在这个文件中openLayers正在创建XMLHttpRequest对象,请求和接收响应。我还发现,在这个阶段已经接收的数据有编码问题。



我还使用wireshark嗅探通信,以确保我发送的数据是正确的编码(utf -8)。我倾销这些数据,并弄清楚,这是正确的utf-8数据。
但是有趣的是,当我尝试使用iso-8859-1显示我的utf-8数据时,我收到的输出与Android浏览器中的完全一样。



我的结论:
在Android 2.2网络浏览器中,XMLHttpRequest对象总是在读取数据时假设使用iso-8859-1编码。



我的解决方案:
你必须自己修复字符串。首先你必须制作地图,你必须记住,例如ø是ø。然后通过字符检查字符,当你找到â序列替换为ø。这是示例代码:

  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;
}

$ b b

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.

解决方案

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;
}

这篇关于Sencha Touch,OpenLayers,GeoServer:使用Android 2.2的设备上的编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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