我无法在axios的响应对象中读取set-cookie头信息。我正在将用户/密码发送到后端,并且响应中的授权cookie在Set-Cookie头信息中,但是我无法在res.header对象中看到它,然而,如果我使用Chrome开发工具并打开网络选项卡,我可以在响应头信息中看到cookie。
有什么线索吗?
我的post请求: axios.post( endPointLogin, { email, password }, { withCredentials: true } )
控制台中的res对象: The res object in console Chrome开发工具中的头部,包含set-cookie头信息: the header on chrome dev tools with the set cookie header
有什么线索吗?
我的post请求: axios.post( endPointLogin, { email, password }, { withCredentials: true } )
控制台中的res对象: The res object in console Chrome开发工具中的头部,包含set-cookie头信息: the header on chrome dev tools with the set cookie header
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
**在Google Dev工具的网络选项卡中查看响应头信息**
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