【发布时间】:2016-11-08 05:25:46
【问题描述】:
所以这个问题问了好几次,但我还是想不通。我正在从 Angular 应用程序向 php 服务发送 http 请求。我需要访问我从浏览器设置的 cookie。我知道要从 php 服务访问 cookie,我必须在我的 http 请求中设置 withCredentials。但随后又引发了通配符错误。
这里是http请求
$http({
url : $scope.urlDomain+ "setting/getAll?skip=0&take=10&orderby=asc",
method :"POST",
headers : {
securityToken : "1124"
},
withCredentials: true
})
我已经在我的 php 文件中设置了标题
header("Access-Control-Allow-Origin: * ");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT,POST, GET, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: origin, x-requested-with, content-type, securityToken");
这是错误
XMLHttpRequest cannot load http://localhost/services/getAll?skip=0&take=10&orderby=asc. Response to preflight request doesn't pass access control check: 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. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute
我坚持了一天,但仍然无法解决这个问题。谢谢大家
【问题讨论】: