HttpClient Subscribed Response Headers Undefined

后端 未结 2 1172
难免孤独
难免孤独 2021-01-19 03:53

can anyone give me any reasons on why I\'m not getting any headers when getting a response back from http.post?

this.http.post(url, body).sub         


        
相关标签:
2条回答
  • 2021-01-19 04:23

    To observe a response instead of a typecasted body, which the newer HttpClient does by default:

    this.http.post(url, data, {observe: 'response'}).subscribe((res:Response) => {});
    

    Ie. what you were doing was just type casting the data your server sent as <Response>.

    0 讨论(0)
  • 2021-01-19 04:43
    Just import Response from `@angular/http` or `@angular/common/http`
    reference official doc : https://angular.io/guide/http
                             https://alligator.io/angular/angular-5/
                             https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced
    
    0 讨论(0)
提交回复
热议问题