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


    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/ 加个全局的配置类 

  • 相关阅读:
    数据结构学习笔记——插入排序
    SpringBoot项目为什么需要引入大量的starter?如何自定义starter
    cin处理用户异常输入
    Redis数据库 ---- 五种数据类型常用命令汇总
    java 获取本周开始时间
    React
    基于ARM+FPGA的ISA总线/MMи总线接口转换设计在轨道交通的应用
    正版Adobe软件来了!Adobe全球唯一正版全家桶订阅只需0元/年
    [机缘参悟-52]:交浅言深要因人而异
    学习编程的第十九天
  • 原文地址:https://blog.csdn.net/u014285237/article/details/126603396