码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 前后端分离项目由于同源策略导致的跨域问题


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

  • 相关阅读:
    线程常用方法与守护线程
    VS调试、debug和release、栈区底层简单介绍、const 修饰指针变量介绍
    计算机毕业设计Java企业级博客系统(源代码+数据库+系统+lw文档)
    两行CSS让页面提升了近7倍渲染性能!
    Bootstrap-- 媒体特性
    百度主动推送不能用了,百度自动推送代码送给大家
    Win10 CMD命令大全 命令提示符常用命令有哪些
    开源作品:引流宝!集活码、短网址等功能为一体的工具!致力于提高引流效率,减少资源流失!
    高速公路智能管理系统:构建安全畅通的数字大动脉
    云南白药Java后端面经
  • 原文地址:https://blog.csdn.net/u014285237/article/details/126603396
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号