0

我试图从服务器访问x-auth令牌。但我没有得到预期的结果。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我得到了价值。以下是我迄今为止尝试过的代码

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);
        })

我不知道如何访问令牌。请帮助。

4

1 回答 1

2

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

console.log(response.headers.get("x-auth"));
于 2019-05-01T12:16:22.883 回答