Problem with HTTPClient...is there a way to close properly the session ?
Hi,
I have one problem with the object HTTPClient.
On my app, I have a window where the user can download a file (by clicking on a button.
Here, the code I use for the download :
httpClient = Titanium.Network.createHTTPClient();
httpClient.setTimeout(10000);
httpClient.onload = function()
{
Ti.API.info('on load');
// Download is ok!!!
};
httpClient.ondatastream = function(e)
{
Ti.API.info('on data stream '+e.progress);
};
httpClient.onerror = function(e)
{
Ti.API.info('error '+e.error);
};
if ( Titanium.Network.online ) {
httpClient.open('GET',"http://myserver/myfile");
httpClient.send();
}
This code works fine if the user waits that the download is complete, but if the user doesn't wait, and click for example on the back button while the file is downloading, the download is stopped, but there is an important problem when the user returns on the download page…If he didn't wait that download was complete, it is now impossible to start the download! I get a time out error, and I can't download the file anymore (I have to close the app, and re-open it, to be abble to download again…).
I've tried to use the abort function on the close event of my download window, but it doesn't work…
Do you know if there is a way to close properly an HttpConnection or something like that in order to resolve my problem ?
Thanks, for your help.
4 Answers
-
try to Provide Back button click option such that
if (download is in progress)
httpClient.close(); && delete the file if exists which is downloaded
else
provide back navigation procedure -
close() no, but abort() does exists :)
-
Can you add a random string to the end of the file?
httpClient.open('GET',"http://myserver/myfile?"+ Math.random() );
-
I am facing the same issue but while uploading the file. any help? our problem is: we start file upload. if user wait till the file get uploaded then no problem. if user cancelled the upload and try to send any webservice to the same server it get timedout.