所以这个问题要问几次,但我仍然无法解决这个问题。我从角应用程序发送http请求到PHP服务。我需要访问我从浏览器设置的cookie。我知道要从php服务访问cookie,我必须在我的http请求中设置 withCredentials 。但再次出现 wilcard 错误。
这是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
我坚持了这一天,仍然无法解决这个问题。谢谢你们
答案 0 :(得分:2)
启用header("Access-Control-Allow-Origin: * ");
时无法使用withCredentials
,您必须指定如下域名:
header("Access-Control-Allow-Origin: 127.0.0.1");
header("Access-Control-Allow-Origin: domain2");
header("Access-Control-Allow-Origin: domain3");