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

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

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
  • ...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744279682a4566508.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信