小编abd*_*lah的帖子

在 ionic 4 上使用 Angular 7 后出现 Cors 策略错误

我很沮丧地发布了类似的问题,但花了 3 天多的时间却无法解决问题。

\n\n

平台:Ionic 4 Angular 7

\n\n

当我尝试发布时,出现 cors 政策错误。

\n\n

从来源 \' http://localhost:8100 \' 访问 \' https://mersinders.com/api/service.php?run=giris \'处的 XMLHttpRequest已被 CORS 策略阻止:对预检请求的响应不会未通过访问控制检查:它没有 HTTP 正常状态。

\n\n

当我禁用 chrome 安全性时,一切正常。

\n\n
\n

“C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe”\n --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp

\n
\n\n

HttpErrorResponse\xc2\xa0{标头:HttpHeaders,状态:400,statusText:“错误请求”,url:“ https://mersinders.com/api/service.php?run=giris ”,好的:false,\xc2\ xa0\xe2\x80\xa6}

\n\n

在 Php api 端使用以下标头后,问题开始出现。

\n\n
\n

header(\'状态: 400\', TRUE, 400); header(\'状态: 404\', TRUE, 404);

\n
\n\n

我有 config.ini.php 其中包括数据库信息和连接,以及 service.php 切换大小写 "service.php?run=XXXXX" 。

\n\n

当我在 service.php 中设置标头时

\n\n
\n

header(\'Access-Control-Allow-Origin: *\');
\n header("Access-Control-Allow-Credentials: true");
\n …

php header cors angular-http ionic4

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular-http ×1

cors ×1

header ×1

ionic4 ×1

php ×1