Same origin policy
Chrome: Origin null is not allowed by Access-Control-Allow-Origin 的问题
发送 http request 时遇到 error: Origin null is not allowed by Access-Control-Allow-Origin。错误是由于 chrome 出于安全考虑禁止直接访问本地文件。
Origin
nullis the local file system, so that suggests that you're loading the HTML page that does theloadcall via afile:///URL (e.g., just double-clicking it in a local file browser or similar). Different browsers take different approaches to applying the Same Origin Policy to local files.My guess is that you're seeing this using Chrome. Chrome's rules for applying the SOP to local files are very tight, it disallows even loading files from the same directory as the document. So does Opera. Some other browsers, such as Firefox, allow limited access to local files. But basically, using ajax with local resources isn't going to work cross-browser.
If you're just testing something locally that you'll really be deploying to the web, rather than use local files, install a simple web server and test via
http://URLs instead. That gives you a much more accurate security picture.
Origin null 是本地文件系统,这个错误说明你通过 file:// URL 加载 html page(例如,在一个本地浏览器文件上双击以打开它)。不同的浏览器采取不同的策略来处理本地文件。
解决方法是安装一个简易的 web server 然后通过 http:// URLs 来测试。
原文:http://stackoverflow.com/questions/8456538/origin-null-is-not-allowed-by-access-control-allow-origin
http://stackoverflow.com/questions/5224017/origin-null-is-not-allowed-by-access-control-allow-origin-in-chrome-why
另外,Firefox 对此更为宽容。如指定 Chrome,也可以在启动时加上:--allow-file-access-from-files 参数。
在使用 local file 请求 XMLHttprequest 时,出现 readyState = 4 而 status = 0 response不成功的情况,此时 response 成功,包的内容也正确。
解答:http://stackoverflow.com/questions/5005960/xmlhttprequest-status-0-responsetext-is-empty
还是浏览器对 same origin policy 要求导致。
Same origin policy的更多相关文章
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9001/api/size/get. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http:/ ...
- Same Origin Policy 浏览器同源策略详解
同源策略 Same Origin Policy 日常开发中最常与网络打交道,那关于浏览器的同源策略和跨域相关的知识是该整理一下了. 首先需要明确的是,同源策略是浏览器的安全策略,由于存在这个策略,我们 ...
- 前端开发必须说的那些事之——同源策略(same origin policy)
同源策略指的是三个相同 协议相同 域名相同 端口相同 如https://www.baidu.com/hahah.html这个网址来说 https是使用的协议,www.baidu.com是域名,端口号默 ...
- 为什么ajax 必须同源,same origin policy
ajax 所有请求都会附带主域的cookie, 若没有同源策略,攻击者就可以获取你的cookie,状态.
- Content Security Policy (CSP) 介绍
当我不经意间在 Twitter 页面 view source 后,发现了惊喜. <!DOCTYPE html> <html lang="en"> <h ...
- 通过扩展让ASP.NET Web API支持JSONP
同源策略(Same Origin Policy)的存在导致了"源"自A的脚本只能操作"同源"页面的DOM,"跨源"操作来源于B的页面将会被拒 ...
- JavaScript学习总结(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例
一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...
- jQuery的$.ajax
在介绍JSONP之前,先简单的介绍一些JSON.JSON是JavaScript Object Notation的缩写,是一种轻量的.可读的基于文本的数据交换开放标准.源于JavsScript编程语言中 ...
- net-force.nl/programming writeup
从 wechall.net 到 net-force.nl 网站,发现网站的内容不错,里面也有不同类型的挑战题目:Javascript / Java Applets / Cryptography / E ...
随机推荐
- jquery 修改input输入框的 readOnly属性 && input输入框隐藏
html的代码 <div class="control-group"> <label class="control-label required&quo ...
- stm32 调试时卡在LDR R0, =SystemInit
网上找到的可能的原因 堆栈空间默认的太小 默认startup_stm32f10x_hd.s中 Stack_Size EQU 0x00000400,如果改大之后,可能调试就可以正常运行. 出现最多的情况 ...
- java连接mysql数据库中文乱码问题
private static final String URL="jdbc:mysql://localhost:3306/ziye?useUnicode=true&character ...
- Jmeter关联-获取token值
1. token就是令牌,比如你授权(登录)一个程序时,他就是个依据,判断你是否已经授权该软件:也叫关联 2. cookie就是写在客户端的一个txt文件,里面包括你登录信息之类的,这样你下次在登录某 ...
- django2
八 Models 数据库的配置 1 django默认支持sqlite,mysql, oracle,postgresql数据库. <1> sqlite django默认使用sqlit ...
- POJ-1679 The Unique MST,次小生成树模板题
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Description Given a connected undirec ...
- [cf360 div1.C]The Values You Can Make[Dp]
题意:有n个硬币,面值不同,求能组成K的方案中,每个方案的硬币可以凑成那些答案. 例如, K=5 面值={1,1,1,2,3} K={1,1,1,2} K={1,1,3} K={2,3} 那么答案是 ...
- POJ 2431 Expedition【贪心】
题意: 卡车每走一个单元消耗一升汽油,中途有加油站,可以进行加油,问能否到达终点,求最少加油次数. 分析: 优先队列+贪心 代码: #include<iostream> #include& ...
- 【动态规划】最长上升子序列(LIS)
今天看了<挑战程序设计竞赛>的动态规划部分,感觉对以前一些知其然却不知其所以然的问题有了更好的理解,先整理一部分. 题意: 有一个长为n的数列a0,a1,a2,...,an .请求出这个序 ...
- HDU——2874 Connections between cities
Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...