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

痞子三分冷 提交于 2019-12-01 10:37:34
Gregor Doroschenko

The Response of new HttpClient is JSON by default. If you want to get the response in another format, you can set it via requestOption responseType: 'text'. Here is some more information about this implementation: https://angular.io/guide/http#requesting-non-json-data

An example:

this.http.get('assets/a.txt', { responseType: 'text' }).map((res:Response) => 
res).subscribe((data: any) => {
  console.log(data);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!