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 May 31, 2015 at 23:29
  • both $http and $httpProvider are Okay
    – Rebornix
    Jun 1, 2015 at 1:55

Your Answer

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

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