2

This is working fine in angular js

$http.defaults.headers.post['X-CSRFToken'] = $cookies['csrftoken'];
$http.defaults.headers.put['X-CSRFToken'] = $cookies['csrftoken'];
$http.defaults.headers.patch['X-CSRFToken'] = $cookies['csrftoken'];

But this is not working

$http.defaults.headers.delete['X-CSRFToken'] = $cookies['csrftoken'];
0

1 Answer 1

2

Per Angular $http document, Angular only have three default headers configuration: common, put and post.

To add headers for an HTTP method other than POST or PUT, simply add a new object with the lowercased HTTP method name as the key

$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }.

So in your case,

$httpProvider.defaults.headers.delete = { 'X-CSRFToken' : $cookies['csrftoken'] }.
2
  • do i need to use $http or $$httpProvider Commented May 31, 2015 at 23:29
  • both $http and $httpProvider are Okay
    – Rebornix
    Commented Jun 1, 2015 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.