Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23127] Windows: Ti.Network.HTTPClient.setRequestHeader is crashing

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-04-01T12:55:21.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 5.3.0
ComponentsWindows
Labelsn/a
ReporterJörgen Buder
AssigneeKota Iguchi
Created2016-03-31T07:53:08.000+0000
Updated2016-04-15T16:26:45.000+0000

Description

the setRequestHeader of the HTTP obj is not working, when used the send() crashes all the time If I remove the setRequeestHeader and handle the type by default in the back then the send() works again.. We need of course this feature in windows.. Example code:
var http = Ti.Network.createHTTPClient({
		onload: function() {
			Ti.API.info('API: step onload');
			var res = JSON.parse(this.responseText);
			

		},
		onerror: function(error) {
			Ti.API.info('API: step onerror');
			
		},
		timeout: 90000
	});
	
	http.open('POST', url);
	*// If I unmark the setRequestHEader the below send() crashes..*
	//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	http.send(data);

Comments

  1. Christopher Williams 2016-03-31

    [~buder] Just for curiosity's sake, what if you use the header name "Content-Type" (case must match) instead of "Content-type"?
  2. Jörgen Buder 2016-03-31

    Hi Argh, I will try this now, how ever for Android and iOS the current "Content-type" has been working for us without any crashes, I will get back to you. It only crashes for Windows.. /Jörgen
  3. Ewan Harris 2016-04-12

    Verified using: Windows 10 Pro Visual Studio 2015 Community Update 2 Appc Core: 5.3.0-12 Appc NPM: 4.2.5-1 Ti SDK: 5.3.0.v20160411153728 Windows Phone Emulator 8.1, 10 Lumia 930 10 Lumia 520 8.1 When using setRequestHeader, if the header does not match the expected case then the app no longer crashes and the request is successful
       var win = Ti.UI.createWindow({backgroundColor:'red'});
       
       win.addEventListener('open', function() {
           var http = Ti.Network.createHTTPClient({
               onload: function() {
                   Ti.API.info('API: step onload');
                   alert('ok')
                   // var res = JSON.parse(this.responseText);
                   Ti.API.info('x' + res);
               },
               onerror: function(error) {
                   Ti.API.info('API: step onerror');
       
               },
               timeout: 90000
           });
       
           http.setRequestHeader("content-type", "application/x-www-form-urlencoded");
           http.setRequestHeader("accept", "text/html");
           http.open('POST', 'http://www.appcelerator.com/');
       
           http.send('TIMOB-23127');
       });
       win.open();
       
       
       var win = Ti.UI.createWindow({backgroundColor:'red'});
       
       win.addEventListener('open', function() {
           var http = Ti.Network.createHTTPClient({
               onload: function(e) {
                   Ti.API.info('API: step onload');
                   alert('ok');
               },
               onerror: function(error) {
                   Ti.API.info('API: step onerror');
       
               },
               timeout: 90000
           });
       
          	http.setRequestHeader('authorization', 'Basic dXNlcjpwYXNzd2Q=');
           http.open('GET', 'http://httpbin.org/basic-auth/user/passwd');
       
           http.send();
       });
       win.open();
       
    Closing ticket

JSON Source