tornado处理跨域问题
报错信息一:
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实现原理和机制不了解导致。
tornado处理跨域问题的更多相关文章
- tornado django flask 跨域解决办法(cors)
XMLHttpRequest cannot load http://www.baidu.com. No 'Access-Control-Allow-Origin' header is present ...
- tornado 添加请求头进行允许跨域
什么是跨域? 这个例子是csdn找的, 声明下哈 什么是跨域? 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器施加的安全限制. 所谓同源是指,域名,协议,端口均相同, ...
- python3 tornado api + angular8 + nginx 跨域问题
问题: 上一个博客部署好了api之后,前端开始吊发现了跨域的问题. 接口地址: http://111.231.201.164/api/houses 服务器上使用的是nginx转发 数据: 前端ang ...
- Tornado—添加请求头允许跨域请求访问
跨域请求访问 如果是前后端分离,那就肯定会遇到cros跨域请求难题,可以设置一个BaseHandler,然后继承即可. class BaseHandler(tornado.web.RequestHan ...
- tornado跨域解决方法
代码 class BaseHandler(tornado.web.RequestHandler): # 允许跨域访问的地址 def allowMyOrigin(self): allow_list = ...
- AJAX请求和跨域请求详解(原生JS、Jquery)
一.概述 AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. AJAX = 异步 JavaScript 和 XML,是一种用于创建快速动态网页的技术.通过在后台与服务器进行少量数 ...
- ajax跨域原理和cors跨域资源共享
不需要设置前端太多,只需要在服务端是在请求头,使服务端的回复数据可以正常通过浏览器的限制,进入网站 首先说下简单请求和非简单请求: 简单请求:必须满足下列条件 1.请求方式:head,get,post ...
- Ajax与跨域Ajax
Ajax 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上.对于传统的Web应用,一个简单操作需 ...
- 解决跨域(CORS)问题
为什么会有跨域问题 是因为浏览器的同源策略是对ajax请求进行阻拦了,但是不是所有的请求都给做跨域,像是一般的href属性,a标签什么的都不拦截 解决跨域问题的两种方式 JSONP 推荐参考 CO ...
随机推荐
- LeetCode 5216. 统计元音字母序列的数目(Java)DP
5216. 统计元音字母序列的数目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i', 'o', ...
- Keyboarding
题目描述 思路 一开始想先写一个bfs,目标字符串要加上一个'*',表示这是一个换行符,然后一个字母一个字母的找,每次重置一下vis数组,bfs返回的结果再加上1,表示要打印这个字母,结果第一个样例没 ...
- php的json_encode第二个参数学习及应用
php5.4以上: json_encode($data, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); p ...
- Flannel 原理简析及安装
flannel是CoreOS提供用于解决Dokcer集群跨主机通讯的覆盖网络工具.它的主要思路是:预先留出一个网段,每个主机使用其中一部分,然后每个容器被分配不同的ip:让所有的容器认为大家在同一个直 ...
- 向Spring 容器中注入对象的几种方法
1.使用@Bean 注解,用于注入第三方 jar 包到SpringIOC容器中. 2.使用 @Import({Order.class, Member.class, MyImportBeanDefini ...
- 在linux系统下安装两个nginx以及启动、停止、重起
如果没有安装过nginx请看:linux下nginx部署以及配置详解 1.第一个nginx已经安装完成后,现在安装第二个nginx 启动:sudo /usr/sbin/nginx3 重起:sudo / ...
- Python 将中文、字母转成数字
Outline 把中文汉字或者英文字母或者特殊字符转换成数字. (实质是字符转成对应ASCII码) 转换 将中文汉字转成数字: ord('单个中文汉字') 反转: chr(21704) 将英文字母转成 ...
- [SDOI2008]仪仗队(欧拉函数)
题目 [SDOI2008]仪仗队 解析 这个题,我也不知道他们的soltion是怎么写的这么长的. 我们发现我们一次看一条直线上的第一个点,也就是说,若两个点斜率\(k=\frac{y}{x}\)相同 ...
- 利用position absolute使div居中
外层DIV{position:realtive}内层DIV{positon:absolute;top:50%;left:50%;margin-top:-100px;margin-left:-150px ...
- Jmeter学习笔记(十九)——后置处理器之正则表达式的使用
一.正则表达式提取器的作用 允许用户从服务器的响应中通过使用perl的正则表达式提取值.作为一个后置处理器,该元素会作用在指定范围的取样器,应用正则表达式,提取所需要的值,生成模板字符串,并将结果存储 ...