2017-10-04 4 views
0

私の応答ヘッダーからSet-Cookieを取得する必要があります。私の応答は次のようになります。 enter image description here角2ヘッダーにアクセスする方法

私のコードは次のようになります。

this.http.get(url, {headers: this.getHeaders(token)}) 
     .timeout(this.timeout - this.loginTimeout) 
     .subscribe(res => { 
      var payload = res.json(); 
      var headers = res.headers; 
      var setCookieHeader = headers.get('Set-Cookie'); 
      console.log(setCookieHeader); 

しかしsetCookieHeaderは常にnullです。どのようにこの応答ヘッダーにアクセスする方法はありますか?何か助けてくれてありがとう。すべての

答えて

0

まず私はあなたが最新のhttpにアップグレードする必要があると思うことにimport { HttpClientModule } from '@angular/common/http';imports: [ HttpClientModule ]によってangular 4.3+に来て、あなたの@NgModule

次に、あなたが参照できるhttps://angular.io/guide/http#reading-the-full-response

http 
    .get<MyJsonData>('/data.json', {observe: 'response'}) 
    .subscribe(resp => { 
    // Here, resp is of type HttpResponse<MyJsonData>. 
    // You can inspect its headers: 
    console.log(resp.headers.get('X-Custom-Header')); 
    // And access the body directly, which is typed as MyJsonData as requested. 
    console.log(resp.body.someField); 
    }); 
関連する問題