我无法在 axios 中读取响应对象上的 set-cookie 标头,我将用户/密码发布到后端,并且响应在 Set-Cookie 标头中有授权 cookie,但是我在 res 上看不到它.header 对象,但是如果我使用 chrome 开发工具并打开网络选项卡,我可以在响应标头上看到 cookie。
有什么线索吗?
我的帖子: axios.post( endPointLogin, { email, password }, { withCredentials: true } )
带有设置 cookie 标头的 chrome 开发工具上的标头
export function login(email, password) {
return http.post(
endPointLogin,
{ email, password },
{ withCredentials: true }
);
}
const handleSignIn = async ( e ) => {
e.preventDefault();
const respuesta = await login( cuenta.email, cuenta.password );
console.log( "res:", respuesta );
};
回复:
config: {url: "http://localhost:3000/usuario/auth", method: "post", data: "{"email":"admin@bmw.com","password":"admin"}", headers: {…}, transformRequest: Array(1), …}
data: "OK"
headers:
access-control-allow-credentials: "true"
access-control-allow-headers: "Origin, X-Requested-With, Content-Type, Accept"
access-control-allow-origin: "http://localhost:5000"
connection: "close"
content-length: "2"
content-type: "text/plain; charset=utf-8"
date: "Tue, 03 Nov 2020 15:00:46 GMT"
etag: "W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc""
vary: "Accept-Encoding"
x-powered-by: "Express"
__proto__: Object
request: XMLHttpRequest {__sentry_xhr__: {…}, readyState: 4, timeout: 0, withCredentials: true, onreadystatechange: ƒ, …}
status: 200
statusText: "OK"
__proto__: Object
**谷歌开发工具网络选项卡中的响应标头**
access-control-allow-credentials: true
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept
access-control-allow-origin: http://localhost:5000
connection: close
content-length: 2
content-type: text/plain; charset=utf-8
date: Tue, 03 Nov 2020 15:00:46 GMT
etag: W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc"
set-cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbXByZXNhIjoiYm13IiwiZW1haWwiOiJhZG1pbkBibXcuY29tIiwic2VndXJpZGFkIjoiYWRtaW4iLCJpYXQiOjE2MDQ0MTU2NDZ9.CpIIScbZQCKsyxvc64CJ290fNCUlpKxZ5zBT3JK2tvc; Path=/
Vary: Accept-Encoding
X-Powered-By: Express