最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Refused to set unsafe header "Date" AngularJS - Stack Overflow

programmeradmin5浏览0评论

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                                 

       }
 })

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                                 

       }
 })
Share Improve this question edited Mar 16, 2016 at 14:23 Hamza Zafeer 2,44613 gold badges35 silver badges47 bronze badges asked Mar 16, 2016 at 13:38 mulikevsmulikevs 1911 gold badge4 silver badges18 bronze badges 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? – adam0101 Commented Mar 16, 2016 at 14:26
Add a ment  | 

3 Answers 3

Reset to default 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.

Try changing "Date" to "Request-Date"

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
  • ...
发布评论

评论列表(0)

  1. 暂无评论