繁体   English   中英

Angular4 HTTP请求公共休息API的Cors错误

[英]Cors error with Angular4 http request public rest api

Ĥ您好,我有点困惑,我不知道如何解决核心问题。 这绝对不是服务器的问题,因为我可以通过应用程序外部的所有其余api获得它。

我正在使用以下REST API进行测试

[ http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm][1]

码:

async getData(){
  const url = "http://www.groupkt.com/post/c9b0ccb9/country-and-other-related-rest-webservices.htm";
  const response = await this.http.get(url).toPromise();
  console.log(response)
}
}

的HTML

<button (click)="getData();"></button>

我得到以下错误:

XMLHttpRequest无法加载http://www.groupkt.com/post/c9b0ccb9/country-and-other-related-rest-webservices.htm 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问源' http:// localhost:4200 '。 [1]: http//www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm

试试这个网址http://services.groupkt.com/country/get/all (例如),这是一个WebService示例。 您在代码中使用的url仅仅是The services的描述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM