浏览器/跨域:修订间差异
来自康健生活
< 浏览器
| 第3行: | 第3行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
npm install egg-cors --save</syntaxhighlight> | npm install egg-cors --save</syntaxhighlight> | ||
==== 参考 ==== | |||
* https://developer.mozilla.org/zh-CN/docs/Web/Security/Same-origin_policy | |||
== CORS == | == CORS == | ||
跨域资源共享 | 跨域资源共享 | ||
2020年7月22日 (三) 13:46的版本
引言
同源策略
npm install egg-cors --save
参考
CORS
跨域资源共享
允许浏览器向跨源的后端服务器发出ajax请求
参考
jsonp
跨域标签
Access-Control-Allow-Origin
如果前端发送的请求附带身份验证 withCredentials:true
Access-Control-Allow-Origin: * 时 cookie 不会出现在http的请求头里。换句话说就是如果前端请求如果携带 Cookie 信息,就不能设置 Access-Control-Allow-Origin: *
OPTIONS
OPTIONS 请求无法通过。
OPTIONS 请求是因为前端发送了“非简单请求”,比如 Content-Type: 'application/json',如果后端失误(或者根本不知道有OPTIONS这种请求),就有可能把OPTIONS挡住,导致无法通过。
在不修改后端的情况下解决这个问题的办法,就是调整 Content-Type: 'application/x-www-form-urlencoded',同时将传输的JSON进行一次序列化或者传参的时候将参数 JSON.stringify
error
- Access to font at 'http://192.168.20.121:4044/****' from origin 'http://192.168.1.109:4043' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

No categories