Search code examples
titanium-mobiletitanium-alloy

Correct way of setting up Authorization header? Titanium


This is the request and response:

Request

Header: AUTHORIZATION:WayXwJYTTTJaYfv2

Response

200 (OK)
Content-Type: application/json
{
    "status": "OK"
}

My api call:

exports.APIDeleteRequest = function(url, callback, errorCallback) {
    Ti.API.info('Delete Request is called');
    var req = Titanium.Network.createHTTPClient({
        onload : callback,
        onerror : errorCallback,
        timeout : 60000
    });

    req.open("DELETE", url);
    req.setRequestHeader('Header: AUTHORIZATION', Alloy.Globals.authToken);
    req.send();
};

I am not sure if the way I have set the Request header is the right way under these circumstances. Could someone confirm, thanks.


Solution

  • It should be:

    req.open("DELETE", url);
    req.setRequestHeader('AUTHORIZATION', Alloy.Globals.authToken);
    req.send();