Problem
For reading Google RSS feeds it is required to encode the second url part.
With iOS this is working as expected, with BlackBerry not.
I did some logging using Wireshark an it looks like that during GET the already encoded url gets encoded once more.
See logs below.
actual behavior
wrong encoding during GET
expected behavior
correct encoding
Test case (app.js)
var win = Ti.UI.createWindow({
backgroundColor : 'white',
layout : 'vertical'
});
function reloadFeed(url) {
Ti.API.info('---> url ' + url);
var xhr = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info('---> xhr onload');
Ti.API.info('---> xhr status=' + this.status);
Ti.API.info('---> xhr responseText=' + this.responseText);
var response = JSON.parse(this.responseText);
for (var i = 0, j = response.responseData.feed.entries.length; i < j; i++) {
Ti.API.info('---> xhr responseText Title ' + i + ' =' + response.responseData.feed.entries[i].title);
Ti.API.info('---> xhr responseText Link ' + i + ' =' + response.responseData.feed.entries[i].link);
//Ti.API.info('---> xhr responseText publishedDate ' + i + ' =' + response.responseData.feed.entries[i].publishedDate);
};
},
onsendstream : function(e) {
Ti.API.info('---> xhr onsendstream');
},
onreadystatechange : function(e) {
Ti.API.info('---> xhr onreadystatechange readyState=' + this.readyState);
},
onerror : function(e) {
Ti.API.info('---> xhr onerror ' + e.error);
}
});
// xhr.autoEncodeUrl = false; // << don't help
xhr.open('GET', url);
xhr.send();
}
button = Ti.UI.createButton({
title : 'reload feed',
bottom : 0,
height : '10%',
width : Ti.UI.FILL // << don't work with BlackBerry
});
button.addEventListener("click", function(e) {
//var urlAjax = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=callBack&q=';
var urlAjax = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=';
var urlFeed = 'http://news.google.com/news?ned=us&topic=t&output=rss';
// << this url part has to be encoded
urlFeed = encodeURIComponent(urlFeed);
Ti.API.info('---> encoded urlFeed=' + urlFeed);
reloadFeed(urlAjax + urlFeed);
});
win.add(button);
win.open();
Logs
BlackBerry Titanium App log
[INFO] ---> url http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dt%26output%3Drss
[INFO] ---> xhr onreadystatechange readyState=1
[INFO] ---> xhr onreadystatechange readyState=3
[INFO] ---> xhr onreadystatechange readyState=4
[INFO] ---> xhr onload
[INFO] ---> xhr status=undefined
[INFO] ---> xhr responseText={"responseData": null, "responseDetails": "The specified feed URL is invalid", "responseStatus": 400}
SyntaxError: Unexpected end of input
iOS Titanium App log
[INFO] : ---> encoded urlFeed=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dt%26output%3Drss
[INFO] : ---> url http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dt%26output%3Drss
[INFO] : ---> xhr onreadystatechange readyState=1
[INFO] : ---> xhr onreadystatechange readyState=2
[INFO] : ---> xhr onreadystatechange readyState=3
[INFO] : ---> xhr onreadystatechange readyState=4
[INFO] : ---> xhr onload
[INFO] : ---> xhr status=200
[INFO] : ---> xhr responseText={"responseData": {"feed":{"feedUrl":"http://news.google.com/news?ned\u003dus\u0026topic\u003dt\u0026output\u003drss","title":"Sci/Tech - Google News","link":"http://news.google.com/news?ned\u003dus\u0026amp;hl\u003den\u0026amp;topic\u003dt","author":"","description":"Google News","type":"rss20","entries":[{"title":"Google switches on Google+ sign-ins, in-app posting - CNET","link":"http://news.google.com/news/url?sa\u003dt\u0026fd\u003dR\u0026usg\u003dAFQjCNF_NsAUYYOMNGi85B_CJLUDYpCp8A\u0026url\u003dhttp://news.cnet.com/8301-10812_3-57571255/google-switches-on-google-sign-ins-in-app-posting/","author":"","publishedDate":"Tue, 26 Feb 2013 08:09:18 <<more text here>> "responseDetails": null, "responseStatus": 200}
[INFO] : ---> xhr responseText Title 0 =Google switches on Google+ sign-ins, in-app posting - CNET
[INFO] : ---> xhr responseText Link 0 =http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNF_NsAUYYOMNGi85B_CJLUDYpCp8A&url=http://news.cnet.com/8301-10812_3-57571255/google-switches-on-google-sign-ins-in-app-posting/
[INFO] : ---> xhr responseText Title 1 =Pluto's smallest moon may be named 'Vulcan' - Financial Express
[INFO] : ---> xhr responseText Link 1 =http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGTAtW-D76E5l1yU5fOMPh-8_Jpzg&url=http://www.financialexpress.com/news/plutos-smallest-moon-may-be-named-vulcan/1080092
[INFO] : ---> xhr responseText Title 2 =Samsung announces new Galaxy smartphone launch - The Guardian
[INFO] : ---> xhr responseText Link 2 =http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNHvMVry7ufpmDzieZ9CiQOtboljTQ&url=http://www.guardian.co.uk/technology/2013/feb/25/samsung-announces-new-galaxy-smartphone-launch
….<<more lines here>>
BlackBerry Wireshark log
GET /ajax/services/feed/load?v=1.0&num=10&q=http%253A%252F%252Fnews.google.com%252Fnews%253Fned%253Dus%2526topic%253Dt%2526output%253Drss HTTP/1.1
Connection: Keep-Alive
Accept-Encoding: gzip
Accept-Language: en-US,*
User-Agent: Mozilla/5.0
Host: ajax.googleapis.com
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 26 Feb 2013 16:31:12 GMT
Content-Type: text/javascript; charset=utf-8
X-Embedded-Status: 400
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
65
{"responseData": null, "responseDetails": "The specified feed URL is invalid", "responseStatus": 400}
0
iOS Wireshark log
GET /ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dt%26output%3Drss HTTP/1.1
Host: ajax.googleapis.com
Accept-Encoding: gzip
User-Agent: Appcelerator Titanium/3.1.0.v20130223030327 (iPhone Simulator/6.1; iPhone OS; en_US;)
Connection: close
X-Requested-With: XMLHttpRequest
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 26 Feb 2013 16:26:40 GMT
Content-Type: text/javascript; charset=utf-8
X-Backend-Content-Length: 34403
X-Embedded-Status: 200
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close
{"responseData": {"feed":{"feedUrl":"http://news.google.com/news?ned\u003dus\u0026topic\u003dt\u0026output\u003drss","title":"Sci/Tech - Google News","link":"http://news.google.com/news?ned\u003dus\u0026amp;hl\u003den\u0026amp;topic\u003dt","author":"","description":"Google News","type":"rss20","entries":[{"title":"Samsung says it plans to double its tablet ... - CNET","link":"http://news.google.com/news/url?sa\u003dt\u0026fd\u003dR\u0026usg\u003dAFQjCNFTxcyFX4JUWi5bn6Xw1bzloIbgEQ\u0026url\u003dhttp://reviews.cnet.com/8301-13970_7-57571311-78/samsung-says-it-plans-to-double-its-tablet-sales-this-year/","author":"","publishedDate":"Tue, 26 Feb 2013 07:43:39 -0800","contentSnippet":"ZDNetSamsung says it plans to double its tablet ...CNETBut the company warned that smartphone sales growth would likely slow ...","content":"\u003ctable border\u003d\"0\" cellpadding\u003d\"2\" cellspacing\u003d\"7\" style\u003d\"vertical-align:top\"\u003e\u003ctr\u003e\u003ctd width\u003d\"80\" align\u003d\"center\" valign\u003d\"top\"\u003e\u003cfont style\u003d\"font-size:85%;font-family:arial,sans-serif\"\u003e\u003ca href\u003d\"http://news.google.com/news/url?sa\u003dt\u0026amp;fd\u003dR\u0026amp;usg\u003dAFQjCNHAOFvscT3U9dvTZFVctkdM5vCDtA\u0026amp;url\u003dhttp://www.zdnet.com/samsung-galaxy-s4-to-launch-on-14-
...
...
"responseDetails": null, "responseStatus": 200}
The % inside the encoded string gets encoded again to %25, I think.
This ticket has been assigned to Tony. Is that correct for a BlackBerry ticket? Thanks, Matthias
Definitely not, probably more likely should be assigned to Russ McMahon. I'm not sure exactly how it would have been assigned to me.
Thanks Tony!
Also found a bug with accessing the "responseText" multiple times. Duplicate accesses would return an empty string. Fixed.
Verified fixed on: Mac OSX 10.9 Mavericks Titanium Studio, build: 3.2.0.201311122225 Titanium SDK, build: 3.2.0.v20131113094843 CLI: 3.2.0 Alloy: 1.3.0 BlackBerry Simulator: 10.2.0.1791 Feed is obtained successfully and logged in the console as expected. No invalid URL is used when encoding. Closing.