3

I am not able to add Date in the header, every time I add the date I get the error. Refused to set unsafe header "Date"

This is My code;

 $http({
      method: 'POST',
      url: 'https:......',
      data: message,
      headers: {'Content-Type': 'application/x-www-form-urlencoded',
                                'XReference':reference,                                  
                                'Authorization':auth,
                                'Date':unixtimestamp                                 

       }
 })
1
  • Since XmlHttpRequest doesn't allow the Date header to be set, could you use a custom header of a different name for your purposes? Commented Mar 16, 2016 at 14:26

3 Answers 3

3

Beneath $http it uses XmlHttpRequest and XmlHttpRequest isn't allowed to set the Date header as per the standard.

Step 5 states:

Terminate these steps if header is a case-insensitive match for one of the following headers...

and Date is included in that list.

It seems like some browsers allow it and others do not.

Sign up to request clarification or add additional context in comments.

3 Comments

So how can I insert it if it is compulsory?
@KelvinMuli You can't - those headers are automatically set by the browser or disabled.
some browsers allow it and others do not. Which browsers allow it? the XHR spec says "don't do this." So it would be a violation. Maybe older versions I guess.
3

Try changing "Date" to "Request-Date"

Comments

0

Browsers don't allow you to set the date header in AJAX requests. According to the specification:

Terminate these steps if header is a case-insensitive match for one of the following headers:

  • ...
  • Date
  • ...

1 Comment

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.