【发布时间】:2020-09-03 05:17:56
【问题描述】:
我正在尝试使用我在 localhost:8100/ 上的 ionic 应用程序访问 XMLHttpRequest,以访问 wampserver 3.1.7 32 位上的 laravel API 主机。
我已经在 wamp 中做过
1:httpd.conf:我将“#LoadModule headers_module modules/mod_headers.so”更改为“LoadModule headers_module modules/mod_headers.so”。
2:httpd.conf:我添加:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</IfModule>
httpd-vhosts.conf 中的 3 :我在
中添加了“Header set Access-Control-Allow-Origin "*""<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
Header set Access-Control-Allow-Origin "*"
AllowOverride All
Require local
</Directory>
</VirtualHost>
当我尝试在 ionic 到 laravel 之间发出 ajax 请求时,我仍然收到此错误:
Access to XMLHttpRequest at 'http://localhost/cn/public_html/api/auth/login' from origin
'http://localhost:8100' has been blocked by CORS policy: Request header field content-type is not
allowed by Access-Control-Allow-Headers in preflight response.
【问题讨论】:
标签: laravel ionic-framework cors wampserver