V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gooooood
V2EX  ›  问与答

求助跨域访问报错问题

  •  
  •   gooooood · 185 天前 · 272 次点击
    这是一个创建于 185 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在腾讯云普通服务器上建站 imgurl 图床网站,想着用于给自己的程序访问上传/下载。 结果本地访问服务器一直报错,按照网上的方法试了一下,还是有问题。

    请教一下各位这个问题应该如何解决?另外云服务器对这种方式建站然后自己使用存在什么限制吗?

    报错信息:( xxxx 是我的域名)

    Access to XMLHttpRequest at 'http://xxxx' from origin 'http://localhost:7457' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    

    前端 Header 配置:

            res.header("Access-Control-Allow-Origin", "*");
            res.header("Access-Control-Allow-Headers", "X-Requested-With");
            res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
            res.header("X-Powered-By", ' 3.2.1')
            res.header("Content-Type", 'text\/plain; charset=utf-8');
    

    后端 Header 配置:

    header("Access-Control-Allow-Origin: *");
    
    yxisenx
        1
    yxisenx  
       185 天前
    报错提示没有响应标头 `Access-Control-Allow-Origin`, https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1621 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:57 · PVG 00:57 · LAX 09:57 · JFK 12:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.