How do I get http headers in React.js

前端 未结 2 832
傲寒
傲寒 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:56

    It's not possible to access page headers via client JavaScript. You can get these request headers on your server side and then pass them into index.html of your React app. For example:

    //in index.html
    
    ...
      
    
    
    ...
    
    

    Then in your app you can access the headers via window.__INITIAL_HEADERS__ variable.

提交回复
热议问题