1

I use axios to retrieve some data from backend. I send a request and i have a response. I want to read some of my headers. I've tried many things but no one is working. My headers contains the following headers 'content-type', content-length', 'x-wp-total', 'x-wp-totalpages'.

I've tried to get headers using response.headers('content-type') but i am getting error response.headers is not function. I am in trouble.

My question seem to be simple. Which is the syntax to get headers from response ?

enter image description here

Pracede
  • 4,226
  • 16
  • 65
  • 110

3 Answers3

0

Have you looked at https://github.com/axios/axios#response-schema?

  // `headers` the HTTP headers that the server responded with
  // All header names are lower cased and can be accessed using the bracket notation.
  // Example: `response.headers['content-type']`
  headers: {},

Related: Response header fields and CORS

chash
  • 3,975
  • 13
  • 29
0

based on your logs, it should be response.headers["content-type"]. Or you can also call response.headers.contentType usually also works.

Jake Lam
  • 3,254
  • 3
  • 25
  • 44
0

headers is the attribute of response. It is an object not function, so you cannot use it as a function like "headers()". If you want to visit the attribute of headers, you should use '.' or []

Jax
  • 1