我正在开发一个react js - spring boot应用程序,所以我使用JWT + Spring Security来保护rest端点。我开发了spring boot应用程序,以便在响应header.Now中返回如下所示的JWT令牌。我需要使用react JS .How来访问它。我可以实现这一点吗?我正在使用axios从react调用端点。
这是我在使用spring boot登录端点时得到的样例响应。
发布于 2020-06-30 23:02:46
您的问题是如何使用axios访问响应头:
这是一个这样的示例代码:
export const REST_API = axios.create({
baseURL: 'http://localhost:8080/api',
timeout: 10000,
headers: {
'Content-Type': 'application/json',
},
});
然后使用您配置的axios客户端
REST_API.post(`/authenticate`, {
username: 'admin',
password: 'admin',
})
)
.then((res: AxiosResponse<any>) => {
console.log(response.headers.Authorization);
});
希望这能对你有所帮助
https://stackoverflow.com/questions/62658397
复制相似问题