axios  设置  

withCredentials :true

 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

如果 Content-Type是 application/x-www-form-urlencoded

需要用 qs.stringify

$u = $_SERVER['HTTP_REFERER'];
$u = preg_replace('#/$#', '', $u);
header("Access-Control-Allow-Origin: " . $u);//$_SERVER['HTTP_REFERER']
header("Access-Control-Allow-Credentials:true ");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With,X-Custom-Header,Origin, Content-Type, Accept, Authorization');

后端设置Access-Control-Allow-Credentials:true后,要将Access-Control-Allow-Origin指定到具体的域,否则cookie不会带到客户端。

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-07-05
  • 2021-12-06
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-11-08
  • 2021-07-05
  • 2021-11-10
  • 2021-08-21
相关资源
相似解决方案