我有问题,让我的离子应用程序发布到我的API。在我的api上,我设置了以下标头:
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS");
当从Postman或实际网站发帖时,一切正常,我看到这些头文件返回,但一旦我打开我的应用程序并发送请求,它就不再起作用。
GET请求工作正常,只是POST请求被破坏了。我使用以下内容在我的应用程序上发送post请求:
/**
* Post to the API
* @param path Where to go
* @param params What to send
*/
private post(path, params): Promise<any> {
return this.http
.post(this.apiUrl + path, params)
.toPromise()
.then(r => r.json());
}
在我的ionic应用程序中,我得到以下错误
Failed to load resource: Preflight response is not successful
XMLHttpRequest cannot load https://mmcalc.com/api/calculate. Preflight response is not successful
我已经为此绞尽脑汁快15个小时了,我不明白为什么它行不通。
https://stackoverflow.com/questions/50775046
复制相似问题