簡體   English   中英

Angular 5 - 盡管(Set-Cookie)在響應標頭中,但已設置 Cookie

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM