• 关于axios跨域带cookie


    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不会带到客户端。

  • 相关阅读:
    [论文复现笔记]Im2Struct
    深度学习踩坑
    Matlab问题汇总
    Linux网络服务
    探索Blender
    [每日挖坑]20200728
    Ubuntu重启之后显卡挂了
    3D视觉知识点
    [每日挖坑]20200727
    遥感影像相关知识
  • 原文地址:https://www.cnblogs.com/zhaoyun4122/p/9707690.html
Copyright © 2020-2023  润新知