Problem
Most of Japanese webpages use utf-8 encoding, but some pages use old encodings (Shift-JIS or EUC-JP).
charset list (as reference)
http://www.iana.org/assignments/character-sets
But a return value will be set to null if Japanese webpage is acquired using Titanium.Network.createHttpClient.
Test case
I make a sample code which accesses each charset sample webpage and display their results.
var win1 = Ti.UI.createWindow({
backgroundColor: 'white',
});
var text = Ti.UI.createLabel({
text: '',
});
win1.add(text);
win1.open();
charsetTest("http://kangaechu.com/utf8.html");
charsetTest("http://kangaechu.com/shiftjis.html");
charsetTest("http://kangaechu.com/eucjp.html");
function charsetTest(url){
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
if(this.status == 200) {
var html = this.responseText;
if(html == null){
text.text = text.text + url + ' is null.\n\n';
}
else if(html.match(/<body>([\s\S]*)<\/body>/)){
var body = RegExp.$1;
text.text = text.text + url + body;
}else{
text.text = text.text + url + ' is 200, but no body element.\n\n';
}
}else{
text.text = text.text + url + ' status code is ' + this.status + '\n\n';
}
};
xhr.onerror = function() {
text.text = text.text + url + ' status code is ' + this.status + '\n\n';
};
xhr.open("GET", url, false);
xhr.send();
}
result is below:
||OS || UTF-8 || Shift_JIS || EUC-JP ||
|iOS | OK | null | null|
Suggested Fix
To fix this bug, add charset list to TiNetworkHTTPClientProxy.m
See
https://github.com/appcelerator/titanium_mobile/pull/590
Closing bug. Verified fix on: SDK build: 2.0.0.v20120314154741 Titanium Studio, build: 2.0.0.201203132050 xcode: 4.2 Device: iphone 4s (5.0.1)