混合app中客户端允许发送 cookie后,服务器跨域必须设置域名怎么办?

客户端代码:

let xhr = new XMLHttpRequest();
xhr.open('post' , url , true);
xhr.withCredentials = true;
xhr.send(null);

服务端:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');

客户端报错:

Access to XMLHttpRequest at 'http://t.com/index.php' from origin 'null' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

请求头也变成没有完整信息的请求头了:

clipboard.png

请问,混合 app 开发方式下,如何允许客户端携带 cookie ??

阅读 2.3k
1 个回答
header('Access-Control-Allow-Origin: *');

这个一句不能返回*,应该是具体的域名,比如:

header('Access-Control-Allow-Origin: http://t.com');
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题