I am trying to add some custom headers in my api request using AngularJS $http.
buildHttpConfig (url, options) {
var config = angular.extend({
method: 'GET',
headers: {}
}, options || {});
config.headers['Content-Type'] = 'application/json; charset=UTF-8';
config.headers['X-MyCustomHeader'] = {
"instanceId": "abc",
"platform": "Web",
"appId": "efg"
};
config.headers.Accept = 'application/json';
config.url = url;
return config;
}
getDocumentsToPresent (): ng.IPromise<string> {
var url = 'https://localhost:8080/services/xyz/myXYZ';
var deferred = this.$q.defer();
this.$http(this.buildHttpConfig(url, {method: 'GET'})).then(function (data: any) {
deferred.resolve(data);
}, function (err) {
deferred.reject(err);
});
return deferred.promise;
}
Every time I make this request, the custom header automatically added to the 'Access-Control-Request-Headers'. Is there a way to add my custom headers in the global http scope? Thanks.
config.headers["instanceId"] = "abc"and so on to set headers?