How to send X-Auth-Token in request headers

I’m desperate to fix the http request issue

Here’s my server, which works fine with curl

Accept: /

< HTTP/1.1 401 Unauthorized
< Server: nginx/1.6.2
< Date: Tue, 14 Oct 2014 16:22:30 GMT
< Content-Type: application/json
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: no-cache
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
< Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Requested-With, X-Auth-Token
< Access-Control-Expose-Headers: X-Auth-Token
< Access-Control-Allow-Credentials: true
< Access-Control-Max-Age: 86400

But when I use angularjs, i got these

OPTIONS http://api.domain ionic.bundle.js:16271
XMLHttpRequest cannot load http://api.domain Invalid HTTP status code 500

this is my request function, which I implemented in service.js

var config = {
headers: {
‘X-Auth-Token’: token
cache: true
//var storage = window.localStorage;
//window.localStorage.setItem(“key”, “value”);
var respose_json = function () {
var deferred = $q.defer();
$timeout(function () {
$http.get(menu_url, config).success(function (result) {
return result;
}, 500);
return deferred.promise;

    return {
        all: respose_json,
        get: function (id) {
            return respose_json[id];

Help please!

Same problem here!! Did you solve it?

Somewhere in your code put this

$http.defaults.headers.common['X-Auth-Token'] = token;

So it will set globally :slight_smile:

I tried it. Not working and the request get method changed to option.

You almost there… normally when we make CORS, then it will try with OPTION first, if return from server allowing to make CORS then the real request would be made