【发布时间】:2020-01-10 00:05:12
【问题描述】:
我正在尝试在 Angular4 Ionic 应用程序中发布,我已阅读所有堆栈溢出帖子并按照他们所说的做了。在我的 PHP 中,我添加了
header ("Access-Control-Allow-Origin: *");
header ("Access-Control-Expose-Headers: Content-Length, X-JSON");
header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS");
header ("Access-Control-Allow-Headers: *");
我能够成功地从 POSTMAN 发布帖子,但通过在 android 中调试应用程序我得到 ...from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
我只是在 angular4 ionic 应用中尝试一个简单的帖子..
getImages() {
this.http.post(url, {
title: 'foo',
body: 'bar',
userId: 1
})
.subscribe(
res => {
console.log(res);
},
err => {
console.log("Error occured");
}
);
}
【问题讨论】: