Reputation: 4197
I am trying to add a customer header in a request angular js for the first time, but am getting the following error
angular.js:10671Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'x-api-key:' is not a valid HTTP header field name.
Here is my code, at the highest 'app' level:
var movieApp = angular.module('movieApp', ['ngAnimate']);
movieApp.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.headers.common = {
'x-api-key:' : 'key'
};
}])
What am i doing wrong/missing/not understanding? How can I add this header to all (or even one) request?
Upvotes: 1
Views: 556
Reputation: 5919
As the error explains, x-api-key
is not a valid HTTP header field. You can go here for the official documentation, or look at wikipedia. To fix this, you have to pass the api key as parameter in the request body.
Upvotes: 1