Sporadically receiving this error (xhr.onerror) when making HTTP request:
Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x6e09310 {NSUnderlyingError=0x6e1c340 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)", NSLocalizedDescription=A connection failure occurred}
I'd say it works about 25% of this time, and throws this error the other 75%.
4 Answers
Accepted Answer
Just to test, could you try changing the xhr.setTimeout(0); to xhr.timeout = 10000;
The most likely cause for this would be the actual device connection going down or being monetarily broken. Or the the url resource itself going down. (We all get 'fail whales' ;) )
You'd need to share more of the code you're using to do the request to see if there's anything else amiss.
xhr = Titanium.Network.createHTTPClient({enableKeepAlive:false});Seems to have done the trick. It would've been nice to've found this in the documentation. Thanks everyone!
function play_sound() { if (list.contents < 5) { empty.play(); } else { full.play(); }; xhr = Titanium.Network.createHTTPClient(); xhr.setTimeout(0); xhr.onerror = function(e) { Titanium.API.info(e.error); }; xhr.onload = function() { Titanium.API.info(this.responseText); }; xhr.open('POST',uri); xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xhr.setRequestHeader('Authorization',auth); if (Titanium.Network.online) { xhr.send(params); } else { alert('Network unavailable, please try again.'); }; };I've obfuscated some variables for security reasons.
Your Answer
Think you can help? Login to answer this question!