Angular turn off json parser [duplicate]

2019-09-20 15:46发布

问题:

This question already has an answer here:

  • Why httpclient in angular 4 is assuming that request am sending json data 1 answer

The server responses with plain text and angular try to parse json. How do i turn of this behaviour in one component?

get(mrn: string): Observable<string> {
    let url: string;
    url = this.Url;
    url = url + '?mrn=' + mrn;
    return this.http.get<string>(url);
  }


download(testobject: Testobject): void {
    this.httpService.get(testobject.mrn)
      .subscribe(ccresult => {
        console.log('ccresult ist: ' + ccresult);
      });
  }

Error: error: SyntaxError: Unexpected token N in JSON at position 0 at JSON.parse () at XMLHttp.......

回答1:

You can get HttpResponse object like this:

this.http.get<any>(url, { observe: 'response' }).map((res): HttpResponse) => ...);


标签: json angular