js Get the data of the request response header

1. Request header

1.Accept
tells the server the data types supported by the client

2.Accept-Encoding
tells the server the data compression formats supported by the client.

3.Accept-Language
tells the server the language environment of the client.

4. The Connection
client tells the server through this header whether to close or keep the connection after the request is completed.

5. Content-Length
indicates the length of the request message body.

6. The Content-Type
client tells the server through this header, the type of data sent by the client to the server.

7. The Cookie
client tells the server through this header that it can bring data to the server.

8. The Host
client uses this header to tell the server the name of the host it wants to visit.

9. Origin
is used to indicate where the request originated, including and only including the protocol and domain name.
This parameter generally only exists in CORS cross-domain requests. You can see that the response has a corresponding header: Access-Control-Allow-Origin.

10. The Referer
client tells the server from which resource it accesses the server through this header. (Generally used for anti-leech)

11. The User-Agent
client tells the server the software environment of the client through this header.

12.Accept-Charset:
Tell the server the encoding used by the client.

13.Date:
The client tells the server through this header that the client is currently requesting time.

14. If-Modified-Since
The client tells the server the cache time of the resource through this header.

Supplement
2. Response header

1.
Through this header, the Connection server responds whether to keep the connection or close the connection.

2. The Content-Encoding
server uses this header to tell the browser the compression format used for the data.

3. The Content-Type
server returns the type of data through this header

4.Date
tells the client the time to return the response.

5. The Server
server uses this header to tell the browser the type of server

6. Transfer-Encoding
HTTP protocol header field Transfer_Encoding, block transfer encoding, generally appears in the response header of http. This header field exists in version 1.1 of the HTTP protocol and provides a data transmission mechanism.
Usually, the http protocol sends the data together as a whole, and the length of the data body is specified by the Content-Length field, which is convenient for judging the end of the message.
Through this header, the server tells the browser the transmission format of the data.

7.
Vary The Vary field is used to list a response field list, telling the cache server how to cache and filter the appropriate version when encountering the same URL corresponding to different versions of the document.

8.
The Location header is used with the 302 status code to tell the client who to look for.

9. The Content-Length
server uses this header to tell the browser the length of the returned data

10. The Content-Language
server uses this header to tell the language environment of the server

11. The Last-Modified
server uses this header to tell the browser the cache time of the current resource

12. The Refresh
server uses this header to tell the browser how often to refresh

13. The Content-Disposition
server uses this header to tell the browser to open the data as a download.

14. ETag: The header related to the cache.
(1) The Expires
server uses this header to tell the browser how long to cache the returned data. -1 or 0 do not cache.

(2) Cache-Control and Pragma
servers can also control the browser not to cache data through this header
—————————————————
Copyright statement: This article is written by CSDN blogger "Firm Chen" Original articles follow the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: https://blog.csdn.net/weixin_42408447/article/details/121396512


      var req = new XMLHttpRequest()
      req.open('GET', document.location, false)
      req.send(null)
      var headers = req.getAllResponseHeaders().toLowerCase()
      var tempCode = req.getResponseHeader('code')
      var token = req.getResponseHeader('access_token')
      if (token) {
        localStorage.setItem('token-weiban', token)
      } else {
        localStorage.setItem('token-weiban', '123')
      }
      var code = '456'
      if (tempCode) {
        code = tempCode
      }
      console.log(headers)

 

 Node sets the html page response header:

const toolsGetPage = async (req, res) => {
  const { code } = req.query
  const tempPage = fs.readFileSync(
    '/source/banxuezhushou_h5/public/weiban/order.html',
    'utf-8'
  )
  if (code === '666') {
    res.setHeader('access_token', Date.now())
    res.setHeader('code', 'code-' + Date.now())
    res.send(tempPage)
    //res.redirect('http://localhost:85/#/h5/index/home/recommend')
  } else {
    res.setHeader('access_token', 'no')
    res.setHeader('code', 'code-' + Date.now())
    res.send(tempPage)
  }
}

Guess you like

Origin blog.csdn.net/xutongbao/article/details/127870135