3

i want to access a header in react js code. I am exposing an API from backend and along with i am sending token to browser in header.

I am consuming this API from ReactJs axios. So how can i access this header in Reactjs

    axios.post(ConstClass.BASE_URL + '/login', this.state).then((response) => {

         console.log(response.headers);

   }).catch((error) => {
       this.setState({
          errorMessage : 'Invalid username and password.'
       });
   });

enter image description here

Sangram Badi
  • 4,054
  • 9
  • 45
  • 78
  • What do you mean "react js code" in your first sentence ? Can you show me that code? Your question has misleading concept. React does not solve the problem of request data. And you can use axios along with React, if it does solve your problem. – Rudy Huynh Jun 23 '18 at 10:28
  • did you mean `this.setState({ login_token: response.headers['x-token'] })` – joaner Jun 23 '18 at 12:27

0 Answers0