【发布时间】:2019-06-28 22:26:38
【问题描述】:
我已经开发了 Woocommerce ionic 应用程序,但是当我将应用程序与实时站点或服务器连接时,它会给出这个错误:
Access to fetch at 'https://www.example.co.uk/shop/wp-json/v3/products/categories?filter[meta]=true&filter[variation]=true'
from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight
request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains
multiple values 'http://localhost:8100, *', but only one is allowed. Have the server send the
header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
为解决此错误,我还将以下代码粘贴到我的服务器 .htaccess 文件中:
Header set Access-Control-Allow-Methods "HEAD, POST, GET, PUT, OPTIONS, PATCH, DELETE"
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type,Credentials"
但它仍然显示相同的错误。
1 个月前它工作正常。 我正在使用 ionic CLI 版本是:3.4.0 和 npm 版本是:6.6.0
【问题讨论】: