我需要幫助,我試圖從響應中獲取cookie,但我找不到方法,我對tsc和ng2很新。Angular 2 - 從響應中獲取Cookie
這是NG2 HTTP POST
return this._http
.post('http://demo...', body, { headers: headers })
.subscribe(
(response: Response) => {
this.storeToken(response);
}, (err) => {
console.log('Error: ' + err);
}
);
這是服務器響應:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
Set-Cookie: JSESSIONID=A099CC4CA7A25DFBD12701630A7DC24C; Path=/pbcp/; HttpOnly
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 17 Feb 2017 04:08:15 GMT
32
{"status":"OK","message":"User is Authenticated."}
0
我很困惑,因爲我看不到它的頭陣...
結果console.log(response)
console.log(response.headers)
...,但我可以看到它在餅乾部分。
謝謝!
試試這個資源。get(「set-cookie」),並讓我知道 –
也嘗試這個多個cookie let resHeader:Headers = res.headers; resHeader.getAll('set-cookie'); –
嗨@Vinay,首先,感謝您的時間。您的建議不起作用,因爲響應中沒有包含該名稱的標題,請參閱我編輯的帖子。嘗試打印這個console.log(response); –