2017-09-26 2 views
0

HttpClient와 함께 요청을 보내고 있으며 응답을 구문 분석 할 수 없습니다. @ angular/http의 http를 사용하면 response.json(). token을 호출해도 문제가되지 않지만 HttpClient에는 존재하지 않습니다. 여기HttpClient from @ angular/common/http

내 요청 :

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

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

응답은 다음과 같습니다 {응답 = { "토큰": "ABCD ... XYZ"}}

HttpClient를이 사용 할 수 없습니다 ? 이전 Http 서비스와는 달리

+0

왜 정상적인 http를 사용하지 않습니까? – mast3rd3mon

+0

기본값은 HttpClient에서'response.json()'입니다. https://stackoverflow.com/questions/45129790/difference-between-http-and-httpclient-in-angular-4 – echonax

답변

0

, 새로운 HttpClient 서비스는 콘텐츠 형식을 생각하고 그에 따라 그것을 구문 분석하려고, 그래서 당신은 이미 개체입니다 response.json()response 때문에 호출 할 필요는 없습니다.

+0

정확히! 정답 – netshark1000