Angular 5-尽管(Set-Cookie)在响应头中,但仍设置了Cookie [英] Angular 5 - Cookie is set although (Set-Cookie) is in the response header
问题描述
对于Angular 5应用程序,我有一个身份验证服务,该服务执行HTTP POST,该HTTP POST返回会话cookie(CORS),如下代码所示:
For an Angular 5 app, I have an auth service that does a HTTP POST which returns the session cookie (CORS) as shown below in the code below:
signIn(signInRequest: SignInRequest): Observable<SignInResponse> {
let headers: Headers = new Headers();
headers.append('Content-Type','application/json');
return this.http
.post("/login", {email: signInRequest._email,password:signInRequest._password}, { headers: headers, withCredentials: true })
.map(this.extractData)
.catch(this.handleErrorObservable);}
标头的响应包含set-cookie,如下所示:
The response of the header contains the set-cookie as shown below:
,请求标头如下:
我知道浏览器应该设置cookie响应.为什么不这样做?
I know that the browser should be setting the cookie response. Why is it not doing it?
推荐答案
您的前端托管在localhost:4200
上,而您的后端托管在api.safra.me
上.默认情况下,除非您使用带有凭据,以及所有后续请求.
Your frontend is hosted on localhost:4200
and your backend is hosted on api.safra.me
. By default, your browser won't send the cookies along the request unless you use the withCredentials in the login request as you already did, and all of the subsequent requests.
这篇关于Angular 5-尽管(Set-Cookie)在响应头中,但仍设置了Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!