• 前后端分离项目由于同源策略导致的跨域问题


    doesn'tbassaccess controd chechsthe vadue of the Acces s-Controd-At1ow-ordein' header sn themes ponse must not be the witacardmiwhen the request"s credentials mode Ls include " . Theeredentiaismode of reauests initiated bor the xoslHttpRecuest Is control1ed byr the withcredentials attnabute-
    *Uncaught (in promise) Error: Network Error
    Chunk-vendors. c69a59f0Lis:320
    at t.exports (chunk-vendons. c6925970.j5:1)
    at XMLHttpRequest.d.onerror
    ve-a6-e-59a59F0lfs:30ay


    2 › OPTIONS htto://10.51.228.35:38763/izc-brn/brain/getAl1 403
    Chunk-vendors. c69a59fe.js:300
     Access to XMLHttpRequest at 'ntto://10.51.228.35:38763/jzc-brain/brain/getAll' from origin http://10.51.228.35' has been blocked by CORS policy: Response to preflight request L=/login:1
    doesn"t pass access control check: No "Access-Control-Allow-Origin' header is present on the requested resource.
    XMLHttpRequest at *http://20.51.228.35:38763/jzc-brain/brain/getAll from origin *nttp://10.51.228.35* has been blocked by CORS policy: Response to preflight request (3/login:1
    snit pass access control check: The value of the *Access-Control-Allow-Origin* header in the response must not be the wildcard
    dentia1s mode of requests initiated by the xvLHEtpRequest is controlled by Ehe withcredentiais attribute:
    IM*1 when the request's credentials mode is 'include*. The
    naught (in promise) Error: Network Error
    shunk-vendors. c69a59f0.js:320
    at .exports (chunk-vendors.c69a59f0-js:1)
    at XMLHttpRequest.d.onerror(chunk-vendons)

     

    1.前端

    axios.defaults.withCredentials  将true改为false
    withCredentials:默认情况下,跨源请求不提供凭据(cookie、HTTP认证及客户端SSL证明等)。通过将withCredentials属性设置为true,可以指定某个请求应该发送凭据。

    默认值为false。
    true:在跨域请求时,会携带用户凭证
    false:在跨域请求时,不会携带用户凭证;返回的 response 里也会忽略 cookie
    当配置了 withCredentials = true时,必须在后端增加 response 头信息Access-Control-Allow-Origin,且必须指定域名,而不能指定为*

    如果后端需要带cookie过去,前端需要设置为true
     

    nginx代理配置nginx.conf

    java后端配置

    1/类或方法上加 @CrossOrigin

    2/ 加个全局的配置类 

  • 相关阅读:
    docker启动前端
    DP1332E多协议高度集成非接触式读写芯片
    Tomcat的安装配置及相关问题解决
    mysql隔离级别RR下的行锁、临键锁、间隙锁详解及运用
    Apache Doris 巨大飞跃:存算分离新架构
    SpringBoot - WebMvcConfigurer的作用是什么?
    Apache DolphinScheduler - 快速扩展 TaskPlugin 从入门到放弃
    Linux命令截取pcap包 前100条报文 输出另一个pcap文件
    射频功率放大器的指标有哪些内容
    jquery datatable+bootstrap popover在表格里弹出对话框时只在表格内部,而不是外部
  • 原文地址:https://blog.csdn.net/u014285237/article/details/126603396