zoukankan      html  css  js  c++  java
  • 一些跨域问题

    问题1:console面板出现Access to Font at 'http://static.anhouse.com/iconfont_c4f1eed.wolf' from origin 'http://static.anhouse.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xf.pinganfang.com' is therefore not allowed access.报错。

    原因:Access-Control-Allow-Origin是HTML5中定义的一种服务器端返回Response header,用来解决资源(比如字体)的跨域权限问题。

    解决方案:需要后端或运维在nginx上添加一个同域的配置,把static这个域添加到同域。
    在nginx.conf中配置

    http {
      ......
      add_header Access-Control-Allow-Origin *;
      add_header Access-Control-Allow-Headers X-Requested-With;
      add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
      ......
    }

    问题2:打开本地html文件时,console面板出现

    Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.报错。

    原因:做本地文件上传,浏览器为了安全性考虑,默认对跨域访问禁止。

    解决方案:给浏览器传入启动参数(allow-file-access-from-files),允许跨域访问。

    Windows下,运行"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" --allow-file-access-from-files

  • 相关阅读:
    2.DI依赖注入
    1.Spring框架入门案例
    5.通过参数注解多个接口参数的用法
    4.update更新和delete删除用法
    3.insert添加用法
    git基础操作
    2.mongodb可视化工具
    12.Scrapy与mongodb交互和设置中间键
    WPF 学习系列汇总
    WPF 4.0 DatePicker 快速录入
  • 原文地址:https://www.cnblogs.com/camille666/p/cross_domain_cases.html
Copyright © 2011-2022 走看看