如何在 React Native 中从 headers 访问 x-auth?

How to access x-auth from headers in react native?

我已尝试从 server.But 访问 x-auth 令牌 我没有从服务器获得预期的 result.The response.headers 控制台输出如下

  Headers { 
    map: {
    connection: "keep-alive"
    content-type: "application/json; charset=utf-8"
    x-auth: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiIxaXBpNG1laiIsImFjY2VzcyI6ImF1dGgiLCJpYXQiOjE1NTY3MDg1NTR9.cOXtbQO_n2vf-HwLmKwyzSi9QcFgh4SghfgCamcLyw4"
    x-powered-by: "Express"
}
    }

我试过控制 x-auth 但我得到错误 auth is not defined。但是当我控制 response.headers.map.connection 我得到 value.Following 是我试过的代码到目前为止

fetch(GLOBAL.LOGIN, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                "requestHeader": {
                    type: "login"
                },
                "loginData": {
                    email_id: this.state.email_id,
                    password: this.state.password
                }
            })
        }).then((response) => {
           console.log(response.headers.map.x-auth);
        })

我不知道如何访问 token.Please 帮助。

在您的 .then 处理程序中,您应该能够访问 header 元素,如下所示:

console.log(response.headers.get("x-auth"));