Http to Httpclient (Angular)

Asked

Viewed 91 times

0

I’m trying to update the requisitions Http for HttpClient in Angular. Currently the code is:

return this.http.get(`${this.url}/grupos`).map(res => res.json());

After researches I’m trying to update this way (unsuccessfully):

return this.httpClient.get(`${this.url}/grupos`, { headers: {'Content-Type': 'application/json'}});

I had some problems with mistakes in GET/Unauthorizing I couldn’t fix.

  • 1

    To access this api you need some token?

  • I believe so, but in the current version no token is sent and works correctly, in what I want to complement followed the same logic of not working with tokens. You think that might be it?

1 answer

0

http client does parse para json automatico then the code:

return this.http.get(`${this.url}/grupos`).map(res => res.json());

flipped:

return this.httpClient.get(`${this.url}/grupos`);
  • Thank you! It had discovered yesterday that the problem was with the same token, the previous http was intercepted and added the token, while the new requests with httpClient were not.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.