我有关于 Angular 4 应用程序的问题。我创建了一个从第三方 API 获取数据的应用程序。我遇到的问题是我的 API 多次调用,但我只发送了一次请求。
经过一些研发后,我发现浏览器正在使用 OPTION 方法运行飞行请求,但在检查了所有 API 后,我发现它们除了飞行请求外,它们正在运行多次。就像一个 API 一样,我请求 API 一次,它运行 4 次 2 次选项和 2 次 GET 请求。我检查了我的代码,只有一次请求正在运行。
我完全理解并同意航班请求。
我分析了我本地的所有调用,结果如下: 1. 所有 GET 调用都有相应的 OPTIONS 调用,根据某些文章,这不是问题 2. 但是,这些调用有多个:
http://localhost:3005/tasks?taskID=1713&singular=1 = 4 Get call, 2 OPTIONS call - why?
http://localhost:3003/resources/30/configs = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/configs = 2 GET cal, 1 OPTIONS call - why?
http://localhost:3003/resources/30/settings = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/settings = 2 GET call, 1 OPTIONS call - why?
这些是 GET 多次的唯一调用。对于所有其他调用,/environments、/settings、/admin、/currentevent、/currentshift.. get 调用只进行一次。
return this.http.get(this.environment.SFDCServiceHost + 'getCurrentEvent?resourceId=' + id + '&singular=1', {headers: this._helperService.setRequestHeader(id)});