报错信息一:

Access to XMLHttpRequest at 'http://localhost:4445/api/v/getmsg' from origin 'http://localhost:9528' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

解决:  将设置的响应头 "Access-Control-Allow-Origin" 修改为特定的域名, 不能使用 "*"

报错信息二:

Access to XMLHttpRequest at 'http://localhost:4445/api/v/getmsg' from origin 'http://localhost:9528' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

解决: 增加一行配置, "Access-Control-Allow-Credentials"  value="true"

报错信息三:

Access to XMLHttpRequest at 'http://localhost:4445/api/v/getmsg' from origin 'http://localhost:9528' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

原因:

浏览器请求接口时会发送两个请求,一个是预请求,相当于确认请求(OPTIONS),第二个请求才是你要发送的真正的请求,而这个错误信息说明的是第一个OPTINOS请求失败,在服务端没有处理这个method为OPTIONS的请求,需要对它处理一下, 服务端只需要再写一个options 方法, 并且返回200状态码即可。

第一种:No 'Access-Control-Allow-Origin' header is present on the requested resource,并且The response had HTTP status code 404

XMLHttpRequest cannot load http://b.domain.com, Response to preflinght request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://a.domain.com' is therefore not allowed access. The Response had HTTP status code 404.

ps.并且The response had HTTP status code 404

问题原因:服务器端后台没有允许OPTIONS请求

第二种:No 'Access-Control-Allow-Origin' header is present on the requested resource,并且The response had HTTP status code 405

XMLHttpRequest cannot load http://b.domain.com, Response to preflinght request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://a.domain.com' is therefore not allowed access. The Response had HTTP status code 405.

ps.并且The response had HTTP status code 405

问题原因:服务器端后台允许了OPTIONS请求,但是某些安全配置阻止了OPTIONS请求

第三种:No 'Access-Control-Allow-Origin' header is present on the requested resource,并且The response had HTTP status code 200

XMLHttpRequest cannot load http://b.domain.com, Response to preflinght request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://a.domain.com' is therefore not allowed access.

ps.并且The response had HTTP status code 200

问题原因:服务器端后台允许了OPTIONS请求,并且OPTIONS请求没有被阻止,但是头部不匹配。

第四种:heade contains multiple values '*,*',并且The response had HTTP status code 200

XMLHttpRequestcannot load http://b.domain.com. The 'Access-Control-Allow-Origin' header contains multiple values'*, *', but only one is allowed. Origin 'http://a.domain.com' is therefore notallowed access.

ps.并且The response had HTTP status code 200

问题原因:设置多次Access-Control-Allow-Origin=*,可能是配置的人对CORS实现原理和机制不了解导致。

最新文章

  1. PHP实现堆排序
  2. Asp.Net 自定义储存Session方式
  3. Windows下给鼠标右键菜单添加获得完全控制权限的菜单项
  4. iOS Xcode7免证书真机调试
  5. 关于SSH整合中对于Hibernate的Session关闭的问题
  6. Apache模块管理
  7. String 、InputStream、Reader 的转换
  8. KoaHub.JS基于Node.js开发的Koa 生成验证码插件代
  9. SpringMVC之简单的增删改查示例(SSM整合)
  10. HTTP 前端需明白的相关知识点
  11. java-索引
  12. mapper代理查询
  13. python中硬要写抽象类和抽象方法
  14. Ubuntu Google Chrome
  15. 事件EVENT与waitforsingleobject的使用以及Mutex与Event的区别
  16. leetcode:Single Number【Python版】
  17. jquery全部版本
  18. 浅谈HashMap与线程安全 (JDK1.8)
  19. 【python教程】Python IDE
  20. Scala实战高手****第9课:Scala类和对象彻底实战和Spark源码鉴赏

热门文章

  1. Python实现双链表
  2. SPFA + 链式前向星(详解)
  3. ajax中如何使用全局变量?
  4. 「UR#6」懒癌
  5. git学习笔记 ---添加远程库
  6. Drools入门
  7. Java11新特性 - 标准Java异步HTTP客户端
  8. vim安装 YCM 过程记录
  9. linux安装mysql后报错启动不了Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
  10. .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖