How can I read the current headers without making a new request with JS? [duplicate]

Active3 hr before
Viewed126 times

5 Answers


The only way what i know to read with javascript the current headers is:,Possible Duplicate: Accessing HTTP Headers in Javascript? ,It's not possible to access page headers via Javascript, without sending ajax request.,But i don't want make a new request, i want read the current headers.

The only way what i know to read with javascript the current headers is:

var req = new XMLHttpRequest();'GET', document.location, false);
var headers = req.getAllResponseHeaders().toLowerCase();

The headers read-only property of the Request interface contains the Headers object associated with the request. , To add a header to the Headers object we use Headers.append; we then create a new Request along with a 2nd init parameter, passing headers in as an init option: , In the following snippet, we create a new request using the Request.Request() constructor (for an image file in the same directory as the script), then save the request headers in a variable: ,PropertiesbodybodyUsed cachecredentials destination headers integrity method mode redirect referrer referrerPolicy url

var myHeaders = request.headers;
load more v

Note that section 14.8 normally prevents a shared cache from saving and returning a response to a previous request if that request included an Authorization header. , The calculation to determine if a response has expired is quite simple: , A "use" of a validator is either when a client generates a request and includes the validator in a validating header field, or when a server compares two validators. , to force any intermediate caches to validate their copies directly with the origin server, or

and clients to explicitly reduce transparency when necessary. However, because non-transparent operation may confuse non-expert users, and might be incompatible with certain server applications (such as those for ordering merchandise), the protocol requires that transparency be relaxed

      -only by an explicit protocol - level request when relaxed by
      client or origin server
load more v

Passing additional data to callback functions,Returns a new Response which is a copy of this Response.,Accessing additional data in errback functions,Return a new Request which is a copy of this Request. See also: Passing additional data to callback functions.

request_with_cookies = Request(url = "",
   cookies = {
      'currency': 'USD',
      'country': 'UY'
load more v

Launch the Visual Studio IDE.,First off, let’s create an ASP.NET Core project in Visual Studio 2019. Following these steps will create a new ASP.NET Core 5 MVC project in Visual Studio 2019.,A new ASP.NET Core 5 MVC project will be created. We’ll use this project to read with request headers in the subsequent sections of this article.,Now consider the following class.

[HttpGet("GetAllHeaders")]public ActionResult<Dictionary<string, string>> GetAllHeaders(){   Dictionary<string, string> requestHeaders =      new Dictionary<string, string>();   foreach (var header in Request.Headers)   {       requestHeaders.Add(header.Key, header.Value);   }   return requestHeaders;}
load more v

Other "headers-current" queries related to "How can I read the current headers without making a new request with JS? [duplicate]"