Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3571] Android: Network - responseText of createHTTPClient invalid for UTF8 encoding

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionWon't Do
Resolution Date2020-01-09T19:01:50.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
Reportersakira
AssigneeIngo Muschenetz
Created2011-04-15T03:46:46.000+0000
Updated2020-01-09T19:01:50.000+0000

Description

Problem

When my app received a UTF-8 text form HTTP Server, the encoding of responseText of Titanium.Network.HTTPClient can be seen invalid. An ASCII text is OK and for iPhone is OK, but for Android, I cannot guess in which encoding method is the received test.

Workaround

We avoid this problem as like below:
var httpc = Ti.Network.createHTTPClient();

httpc.onload = function() {
var canvases = [];
var lines = "";
if (Ti.Platform.osname == 'iphone') {
    lines = this.responseText.split("\n");
} else if (Ti.Platform.osname == 'android') {
    lines = ("" + this.responseData).split("\n");
}
Then, my app can get the desired string in variable 'lines'.

Comments

  1. Paul Dowsett 2011-12-21

    As indicated by the reporter in the original title, this ticket relates to android. Hence, correcting Component field.
  2. Leonardo Leal 2015-01-07

    Explicitly declare the charset on your service's response header, and It will be fixed. I had this very same problem, and It seems that when you don't declare the response charset on the "content-type" header, Android tries to use the current locale of the OS for response texts, which changes from user to user around the world. Set your response header to something like "Content-Type: application/json;charset=utf-8" and your problem will be solved.

JSON Source