Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2961] If I do abort on the HttpClient. Abort is working but if I go back and agin hit the download it thorows bad request eror message in adb logcat

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-08-01T11:48:59.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, httpclient
ReporterSurajit Biswas
AssigneeBetty Tran
Created2012-07-02T05:48:35.000+0000
Updated2016-03-08T07:47:57.000+0000

Description

If I do abort on the HttpClient to cancel the currently on going download. Abort is working but if I go back and aging hit the download it throws bad request error message in adb logcat as below. In iPhone it is working fine but in android it is causing this problem. Abort code: alertDialog = Titanium.UI.createAlertDialog({ title : 'Attachment Download', message : 'Please wait your attachment is downloading', buttonNames : ['Ok', 'Cancel'], cancel : 1 }); alertDialog.show(); Ti.App.abort = false; alertDialog.addEventListener('click', function(e) { Ti.API.info("Abort File DOANLOAD====================="); if(e.index == 1) { Ti.App.abort = true; } alertDialog.hide(); }); //Get the response from the server xhr.ondatastream = function() { if(Ti.App.abort == true) { xhr.abort(); } } Here abort is working but If go back and again try to download it shows me the below error:- 07-02 18:12:38.496: ERROR/TiHttpClient(9697): (TiHttpClient-13) [4017,425618] HTTP Error (org.apache.http.client.HttpResponseException): Bad Request 07-02 18:12:38.496: ERROR/TiHttpClient(9697): org.apache.http.client.HttpResponseException: Bad Request 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:231) 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:190) 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657) 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637) 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1123) 07-02 18:12:38.496: ERROR/TiHttpClient(9697): at java.lang.Thread.run(Thread.java:1019) 07-02 18:12:38.500: INFO/TiHttpClient(9697): (TiHttpClient-13) [5,425623] Sending error Bad Request So please suggest me If I am wrongly using the abort function or any thing I should do.

Comments

  1. Varun Joshi 2012-07-06

    Hi, It would be great if you can provide a complete test case. I tried the sample code below and it seems to be working fine. Clicking on post data and then clicking on cancel in the alert dialog to abort httpclient and then clicking on post data again worked properly. Is this what you are trying to accomplish? A test case would be good to have. {noformat} Titanium.UI.setBackgroundColor('#000'); var win = Ti.UI.createWindow({ backgroundColor : 'white' }); win.open(); var b2 = Titanium.UI.createButton({ title : 'Post data', height : 40, width : 200, top : 120 }); win.add(b2); b2.addEventListener('click', function() { var http = Ti.Network.createHTTPClient(); http.onerror = function(e) { Ti.API.error(e.error); }; http.open('POST', 'http://www.appcelerator.com'); http.send(); Ti.API.info('after send call'); http.onload = function() { var alertDialog = Titanium.UI.createAlertDialog({ title : 'Attachment Download', message : 'Please wait your attachment is downloading', buttonNames : ['Ok', 'Cancel'], cancel : 1 }); alertDialog.show(); Ti.App.abort = false; alertDialog.addEventListener('click', function(e) { Ti.API.info("Abort File DOWNLOAD====================="); if (e.index == 1) { Ti.App.abort = true; } alertDialog.hide(); }); }; http.ondatastream = function(e) { Ti.API.info('ONDATASTREAM1 - PROGRESS: ' + e.progress); if (Ti.App.abort == true) { http.abort(); } }; }); {noformat} Thanks, Varun
  2. Shak Hossain 2014-01-01

    Closing since we have not heard back from Surajit.

JSON Source