0

I'm sending a request with HttpClient and I'm unable to parse the response. With http from @angular/http it isn't a problem to call response.json().token but this doesn't exist on HttpClient.

Here my request:

 return this.httpClient.post(environment.baseUrl + '/api/authenticate', JSON.stringify({ username: username, password: password }))
            .map((response: Response) => {

//response.json() --> leads to an exception
...

the response is: {response = {"token": "abcd...xyz"}}

Is it not possible to use HttpClient for this?

netshark1000
  • 7,245
  • 9
  • 59
  • 116

1 Answers1

0

Unlike the old Http service, the new HttpClient service tries to guess the content type and parse it accordingly, so you don't need to call response.json() because response is already an object.

cyr_x
  • 13,987
  • 2
  • 32
  • 46