Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17047] iOS: HTTPClient callbacks are not triggered for synchronous request

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2014-05-30T22:09:06.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sn/a
ComponentsiOS
Labelsqe-3.3.0, regression
ReporterKajenthiran Velummaylum
AssigneePedro Enrique
Created2014-05-30T05:52:40.000+0000
Updated2017-03-22T20:32:54.000+0000

Description

HTTPClient callbacks are not triggered when HTTPClient synchronous requests. Following callbacks are tested and not triggered in SDK 3.3.0.v20140528144113. Callbacks 1. onload 2. onerror 3. onreadystatechange 4. onsendstream It's a *regression* since it doesn't happen in 3.2.3 GA. *Steps to reproduce:* 1. Run the application with the code below. 2. Check the alert dialogs from the callbacks. *Actual Result:* Alert box are not showing for any callbacks for the synchronous requests. It works for asynchronous requests. *Expected Result:* callbacks should work for both synchronous and asynchronous requests.
var win = Titanium.UI.createWindow({title:'Charset Test window', backgroundColor : 'white'});

var button = Titanium.UI.createButton({title:'OnError Check'});

button.addEventListener('click', function() 
{
	var valid_url = 'http://www.google.com';
	var invalid_url = 'http://www.somethingxx.com';
	
	var xhr = Ti.Network.createHTTPClient();
	
	xhr.onload = function() {
		alert('onload');
	};
	
	xhr.onerror = function() {
		alert('onerror');
	};
	xhr.onreadystatechange = function() {
		alert('statechanged');
	};
	xhr.onsendstream = function() {
		alert('sendstream');
	};
	
	xhr.open('GET',valid_url,false);
        // Uncomment this to check the onerror callback
        //xhr.open('GET',invalid_url,false);
	xhr.send();
});

win.add(button);
win.open();

Comments

  1. Ingo Muschenetz 2014-05-30

    cc [~mlangston]
  2. Pedro Enrique 2014-05-30

    This is a synchronous requests and works as intended. You can get the response properties after making the call. The limitation to this, an Apple NSURLRequest limitation, is that we can't get the progress of the request (onsendstream and ondatastream)
       var win = Titanium.UI.createWindow({title:'Charset Test window', backgroundColor : 'white'});
       var button = Titanium.UI.createButton({title:'OnError Check'});
       button.addEventListener('click', function() {
       	var valid_url = 'http://www.google.com';
       	var invalid_url = 'http://www.somethingxx.com';	
       	var xhr = Ti.Network.createHTTPClient();
       	xhr.open('GET',valid_url,false);
       	xhr.send();
       
           // get error if any:
           Ti.API.info( xhr.error );
       
           // get response text or data
           Ti.API.info( xhr.responseText  );
           Ti.API.info( xhr.responseData );
       
       });
       
       win.add(button);
       win.open();
       
  3. Kajenthiran Velummaylum 2014-05-30

     Ti.API.info(xhr.error ) 
    prints *undefined* for both synchronous and asynchronous type of requests. But if you place some statements inside the callback like this
       xhr.onerror = function()
       {
       	alert('onerror is triggered');
       };
       
    It's not executed for synchronous type requests with the test environment mentioned in description section.
  4. Ingo Muschenetz 2014-05-30

    I'm comfortable with marking this as "Won't Fix". [~bhatfield], can we please make sure this is WELL documented?
  5. Lee Morris 2017-03-22

    Closing ticket as the issue will not fix and with reference to the above comments.

JSON Source