[英]Does Http get of Angular2 only support Json?
UFC-api.service.ts
getFighters() {
return this.http.get('http://ufc-data-api.ufc.com/api/v3/fighters')
.map(res => res.json());
}
fighter.component.ts
data: string;
constructor(private ufcApiService: UfcApiService) { }
clickGetFighter() {
this.ufcApiService.getFighters()
.subscribe(result => {
this.data = JSON.stringify(result);
},
error => {
this.data = error;
},
() => console.log('fighters done!!'));
}
它无法正常工作,并且出现以下错误:
{“ _body”:{},“ status”:0,“ ok”:false,“ statusText”:“”,“ headers”:{},“ type”:3,“ url”:null}
如果我自己制作了宁静的api,这是可行的,但这来自UFC数据API的网站。
有什么方法可以在angular2上使用http get获得html字符串,例如.net上的HttpClient吗?
感谢帮助。
您需要为应用程序提供标题。 在您的情况下,它将是文本/纯文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.