Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1177] iOS: HTTPClient Authorization header NOT being passed

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionFixed
Resolution Date2014-06-18T07:30:42.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsauthorization, header, httpclient, ios
ReporterMinh Nguyen
AssigneeSteven Scott
Created2014-06-17T07:37:21.000+0000
Updated2016-03-08T07:37:33.000+0000

Description

When I run below code on iOS, no Authorization header being passed, but it works well on Android ( Please see response on attachments )
// Simple HTTPClient request with Authorization header
function request(data) {
	var httpClient = Ti.Network.createHTTPClient({
		onload: function() {
		    Ti.API.info( 'SUCCESS --- ' + this.status + '\n\t' + this.responseText );
	    },
	    onerror: function() {	    	
	    	Ti.API.info( 'ERROR --- ' + this.status + '\n\t' + this.responseText );
		}
	});
	
	httpClient.open('GET', 'http://api-minh.rhcloud.com/'); // This API simply echo all Headers being passed.
	
	// Add Basic Authentication Header
	httpClient.setRequestHeader('Authorization', 'Basic ' + Titanium.Utils.base64encode(data.email + ':' + data.token));
	httpClient.setRequestHeader('Content-Type', 'application/json');
	
	// Send
	httpClient.send();
}

request({ email: 'verylonglonglong.name@gmail.com', token: '6557e9dd2d747321ecc65' });

Attachments

FileDateSize
android.png2014-06-17T07:37:21.000+000079218
ios.png2014-06-17T07:37:21.000+000057277

Comments

  1. Minh Nguyen 2014-06-17

    I found exact issue described [here](http://yaymedia.net/?p=1323) and his solution works well.
       var h = Titanium.Utils.base64encode(data.email + ':' + data.token).toString();
       h = h.replace(/[\r\n]+/, '');
       httpClient.setRequestHeader('Authorization', 'Basic ' + h);
       
    Thanks to [Steve Carpenter](http://yaymedia.net/?page_id=4)
  2. Shuo Liang 2014-06-18

    Customer found the resolution.

JSON Source