[英]Angular 5 - Cookie is set although (Set-Cookie) is in the response header
對於 Angular 5 應用程序,我有一個執行 HTTP POST 的身份驗證服務,它返回會話 cookie (CORS),如下面的代碼所示:
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,如下所示:
請求標頭如下:
我知道瀏覽器應該設置 cookie 響應。 為什么不這樣做?
您的前端托管在localhost:4200
上,后端托管在api.safra.me
上。 默認情況下,您的瀏覽器不會隨請求發送 cookie,除非您像之前那樣在登錄請求和所有后續請求中使用withCredentials 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.