How do I get http headers in React.js

前端 未结 2 831
傲寒
傲寒 2021-01-02 03:20

I\'ve made a request to a React page, and I need to get the headers from the request.

I call the page via the URL:

http://localhost/dashboard

and I s

2条回答
  •  别那么骄傲
    2021-01-02 03:35

    You cant get current page headers without sending a http request via javascript. See this answer for more info.

    Add a dummy api url on your server and hit it after your page loadn then you can get the headers.

    class App extends React.Component{
        //some code
        componentDidMount(){
           fetch(Some_API).then(response=>{
               console.log(response.headers)
           })
        }
        //some code
    }
    

提交回复
热议问题