我正在尝试在本地构建一个 jQuery 移动应用程序,通过 XMLHttpRequest/XCRF/JSON 连接到我的网站。当尝试连接到我的网站时,出现以下错误:
XMLHttpRequest cannot load http://wwws.mydomain.com/rest/system/connect.
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.
Origin 'http://localhost' is therefore not allowed access.
我根据 CORS 文档在我的网络服务器 (mydomain.com) 上启用了 CORS:
Header always set Access-Control-Allow-Origin "*"
如何从我的网站外部测试我的网络服务?当它转换为 Android 应用程序时,我会遇到类似的问题吗?
最佳答案
这是安全的一部分,你不能这样做。如果您想允许凭据,那么您的 Access-Control-Allow-Origin 不得使用 *。
关于本地 Javascript 测试 Web 服务 - CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29550746/