Is it possible to use some kind of JavaScript to change or set a HTTP request's header?
相关问题
- Angular RxJS mergeMap types
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- Carriage Return (ASCII chr 13) is missing from tex
- How to fix IE ClearType + jQuery opacity problem i
Using the XMLHttpRequest object, you can use the
setRequestHeader
function.A little code to get you on your way:
The method
setRequestHeader
must be called after open, and before send.More info: https://developer.mozilla.org/en/DOM/XMLHttpRequest#setRequestHeader()
Headers are passed long before javascript is downloaded, let alone interpreted. The short is answer is no.
However, if you're speaking in the context of an ajax call (let's use jQuery as an example), the request headers can be written.
See reading headers from an AJAX call with jQuery. See setting headers before making the AJAX call with jQuery
However, if your javascript is server-side (e.g. node.js) that would be a yes (probably not since the post mentions HTML):