我无法让我的离子型应用程序发布到我的API。在我的API上,我设置了以下标题:
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS");
当从邮递员或实际网站发帖时,一切都按预期工作,我看到这些邮件头又回来了,但一旦我打开应用程序并发送请求,它就不再工作了。
GET请求工作正常,只是POST请求被破坏。我使用以下功能在我的应用程序上发送帖子请求:
private post(path, params): Promise<any> {
return this.http
.post(this.apiUrl + path, params)
.toPromise()
.then(r => r.json());
}
我在我的爱奥尼亚应用程序中得到以下错误
Failed to load resource: Preflight response is not successful
XMLHttpRequest cannot load https://mmcalc.com/api/calculate. Preflight response is not successful
我已经为这件事忙了将近15个小时了,我不明白为什么它不起作用。