Angular 2: How to access an HTTP response body?

后端 未结 10 2044
南方客
南方客 2020-12-13 12:25

I wrote the following code in Angular 2:

this.http.request(\'http://thecatapi.com/api/images/get?format=html&results_per_page=10\').
      subscribe((re         


        
10条回答
  •  不思量自难忘°
    2020-12-13 13:08

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

    this.http.request('http://thecatapi.com/api/images/get?format=html&results_per_page=10')
        .subscribe(response => console.log(response.text()))
    

    That API was deprecated in Angular 5. The new HttpResponse class instead has a .body() method. With a {responseType: 'text'} that should return a String.

提交回复
热议问题