I'm in firefox. Is there a way in javascript to make an http request with only custom headers? ie no cookie fields or user agent or anything, only what my js code specifies.
It should be base js not a library like jquery.
For example, trying to send Http GET without the 'Cookie' header, I tried already:
var myRequest = new XMLHttpRequest();
myRequest.open("GET", "http://asite.com");
myRequest.setRequestHeader("Cookie", '');
myRequest.send();
But I look in the developer console and the request was still sent with the session cookie. I also tried:
myRequest.setRequestHeader("Cookie", null);
您可以使用fetch()
方法,该方法默认情况下将不包含cookie(由于在大多数使用情况下credentials
默认为false)。
Read this: https://fetch.spec.whatwg.org/#forbidden-header-name
This is a list of headers that can NOT be modified/removed in an xmlhttprequest:
Accept-Charset
Accept-Encoding
Access-Control-Request-Headers
Access-Control-Request-Method
Connection
Content-Length
Cookie
Cookie2
Date
DNT
Expect
Host
Keep-Alive
Origin
Referer
TE
Trailer
Transfer-Encoding
Upgrade
Via
or starts with Proxy-
or Sec-
(including when it is just Proxy-
or Sec-
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.