Android & xhr Encoding
I'm taking a look at Android.
I have an app that work perfectly with iPhone. The parsing of my UTF-8 XML is ok and the display in a tableView fine.
But with android all french specific caracters are messed up with encoding pb :
http://yfrog.com/0fcapturedcran20100531010p
I do not have the problem when a create a tableView with local data. So i suspect xhr ….
Any ideas ?
I had the problem in webview but adding the META Content-Type with UTF-8 solved the problem.
Thanks.
4 Answers
-
Can you pastie as snippet of code that points to your URL that we can run through the debugger to see what's happening?
-
I was having exactly the same problem and I think I found a workaround.
In KitchenSink (Resources/examples/xhr_utf8.js), the test for UTF-8 passes a UTF-8 value which is echoed back.
I added an arbitrary argument 'a' with a UTF-8 value:
xhr.send({"a":"€"});
This appears to trigger correct encoding.
-
I had wrongly assumed that adding the UTF-8 parameter had solved the problem.
I added
AddDefaultCharset UTF-8
to the apache config which forces the header:
Content-Type: text/plain; charset=UTF-8
BTW, running
curl -v -o /dev/null http://yfrog.com/0fcapturedcran20100531010p
shows
... Content-Type: text/html ...
-
Are you sure your server reponse content type looks similar to:
Content-Type: application/json; Charset=utf8You can debug it for example with fiddler
If you don't set Charset=utf8, the default character encoding is taken, which is not UTF8 (it's defined in the apache libs) (Line 446)
The UTF8 Strings in the request are not required. (android)
For further info have a look at android source:
https://github.com/appcelerator/titanium_mobile/blob/1_4_1/android/modules/network/src/ti/modules/titanium/network/TiHTTPClient.java#L446