Node.js API调用节点后端后访问标头属性

Node.js API调用节点后端后访问标头属性,node.js,reactjs,Node.js,Reactjs,在react项目中,我对节点后端端点进行api调用。在这个端点中,我返回一个带有x-auth-token头集的响应。代码为 答复如下: res.header('x-auth-token', token).send('User registered') 在react中,我对这个端点进行了一个api调用,我需要提取x-auth-token,并在本地存储中设置它的值。我尝试这样做,但是没有发送响应的标题 以下是react中api调用的代码片段: const response = await

在react项目中,我对节点后端端点进行api调用。在这个端点中,我返回一个带有
x-auth-token
头集的响应。代码为 答复如下:

res.header('x-auth-token', token).send('User registered')
在react中,我对这个端点进行了一个api调用,我需要提取
x-auth-token
,并在本地存储中设置它的值。我尝试这样做,但是没有发送响应的标题

以下是react中api调用的代码片段:

    const response = await axios.post('http://localhost:5000/api/users/', {username: username, email: email, password: password})
    console.log(response.headers.get('x-auth-token'))
在控制台中,我得到:

xhr.js:178 POST http://localhost:5000/api/users/ 400 (Bad Request)
当我在控制台中记录
response.headers
时,会返回以下信息:

{content-length: "15", content-type: "text/html; charset=utf-8"}
content-length: "15"
content-type: "text/html; charset=utf-8"
__proto__: Object
有人知道这里的问题吗?谢谢

xhr.js:178 POST http://localhost:5000/api/users/ 400 (Bad Request)
首先,您必须确保该端点正常工作。事实并非如此。在尝试获取身份验证令牌之前修复此问题


检查您的服务器是否需要POST调用,以及正文的格式是否正确。

问题在于您的端点没有正确响应。对,后端问题