Problem description
When the httpclient request url starts with leading blanks, an exception is thrown when the "send()" function is executed.
{noformat}
message = "-[NSNull rangeOfString:]: unrecognized selector sent to instance 0x3a804690";
{noformat}
Steps to reproduce
Create HTTPClient and use a request url with leading blanks: "
http://www.appcelerator.com"
Test case
(function() {
var urls = [
"http://www.appcelerator.com",
"www.appcelerator.com",
"appcelerator.com",
"http://www.appcelerator2.com",
"http2://www.appcelerator.com",
"http:www.appcelerator.com",
" http://www.appcelerator.com" //exception
];
var win = Ti.UI.createWindow({backgroundColor:'#ffffff'});
var view = Ti.UI.createView({layout:'vertical'});
var button = Ti.UI.createButton({title:' Run test ',top:100,borderRadius:5,borderColor:'#1C1C1C',backgroundColor:'#C0C0C0'});
var output = Ti.UI.createLabel({top: 20,font:{fontSize:11}});
button.addEventListener('click',function(){
output.text = '';
for (var i=0; i < urls.length; i++) {
sendGET(i,urls[i]);
}
});
view.add(button);
view.add(output);
win.add(view);
function sendGET(i,url){
var client = Ti.Network.createHTTPClient({
onload : function(e) {
var msg = 'Test ' + i + ': ' + url + ' - success';
output.text += '\n' + msg;
Ti.API.log(msg);
},
onerror : function(e) {
var msg = 'Test ' + i + ': ' + url + ' - error';
output.text += '\n' + msg;
Ti.API.error(msg);
},
});
client.open("GET", url);
try{
client.send();
}catch(e){
var msg = 'Test ' + i + ': ' + url + ' - EXCEPTION';
output.text += '\n' + msg;
Ti.API.error(msg);
}
}
win.open();
})();
No comments