I wrote the following code in Angular 2:

      subscribe((res: Response) => {

When I print the response I get in console: enter image description here

I want to have access to the body field in the response code The body field starts with an underscore which means that it's a private field When I change it to 'console.log(res._body)' I got an error.

Do you know the getter function that can help me here?

Best Answer

Both Request and Response extend Body. To get the contents, use the text() method.

    .subscribe(response => console.log(response.text()))

This api was deprecated in angular 5 The new HttpResponse<T> class instead has a .body() method. With a {responseType: 'text'} that should return a String .