![](/img/trans.png)
[英]Angular 8 HttpClient GET response not returning the custom headers
[英]Angular 6 HttpClient GET response not returning the custom headers
我是Angular 6的新手,並創建了一個新應用程序來替換我們現有的Angular 1.x應用程序。 我正在像這樣對服務器進行GET調用-
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }),
responseType: 'text' as 'json'
};
return this.http.get(this.domain + '/login', this.httpOptions).pipe(
map((res: HttpResponse<any>) => {
let myHeader = res.headers.get('X-CSRF-TOKEN');
return res;
}
在我的響應標頭中,我得到這樣的信息-
在我的響應回調中,我試圖獲取此令牌信息並將其設置為一些存儲,以作為標頭傳遞給我的未來請求。 但是,我的響應主體是一個HTML文檔-我正在使用它接收
responseType: 'text' as 'json
因此,在我的回調內部,而不是獲取包含標頭的整個響應,而是將HTML文檔作為文本獲取。
為什么我沒有得到標頭和全部的完整響應?
注意:我嘗試完全刪除responseType,但是即使服務器返回200,我總是總是得到HttpErrorResponse。
SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse
所以我保留了responseType。
任何幫助表示贊賞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.