Angular4 http 请求的 Cors 错误 public rest api
Cors error with Angular4 http request public rest api
Ĥ你好,我有点迷茫,不知道怎么用cors解决问题。这绝对不是服务器的问题,因为我每次休息 api 都会得到它,这在我的应用程序之外。
我正在使用以下休息 api 进行测试
[http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm][1]
Code:
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 cannot load
http://www.groupkt.com/post/c9b0ccb9/country-and-other-related-rest-webservices.htm.
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:4200' is therefore not allowed
access. [1]:
http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm
试试这个 Url http://services.groupkt.com/country/get/all(例如),这是一个 Web 服务示例。您在代码中使用的 url 只是对服务的描述。
Ĥ你好,我有点迷茫,不知道怎么用cors解决问题。这绝对不是服务器的问题,因为我每次休息 api 都会得到它,这在我的应用程序之外。
我正在使用以下休息 api 进行测试
[http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm][1]
Code:
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 cannot load http://www.groupkt.com/post/c9b0ccb9/country-and-other-related-rest-webservices.htm. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. [1]: http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm
试试这个 Url http://services.groupkt.com/country/get/all(例如),这是一个 Web 服务示例。您在代码中使用的 url 只是对服务的描述。