我正试图从此webapi获得响应:
https://exchangeratesapi.io/api/latest?base=EUR&symbols=USD,CAD
我只需要使用http GET直接调用它即可。
如您所见,如果您使用浏览器点击了链接,则该链接有效,但如果我尝试 在Angular2中调用它会出现405错误...
这是代码:
Get_ExchangeRate_FromApi(): Observable<ApiExchangeRateResponse> {
var url = "https://exchangeratesapi.io/api/latest?base=EUR&symbols=USD,CAD";
var headers = new RequestOptions({
headers: new Headers({
})
});
return this.http.get(url, headers)
.map(response => response.json())
.catch();
}
我该如何解决?
答案 0 :(得分:1)
private url:String = "https://exchangeratesapi.io/api/latestbase=EUR&symbols=USD,CAD";
Get_ExchangeRate_FromApi(){
return this.http.get(this.url)
.map((response:Response) => response.json());
}
this.Serviceobject.GetJson()
.subscribe(
data => {
this.getResponseVariable = data
},
error => alert(error),
() => console.log(this.getLoginRes)
);
只需尝试