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 ...
 
随机推荐
- TCP传输的三次握手四次挥手策略
			
为了准确无误地数据送达目标处,TCP协议采用了三次握手策略.用TCP协议把数据包送出去后,TCP不会对传送后的情况置之不理,它一定会向对方确认是否成功送达.握手中使用了TCP的标志:SYN和ACK 发 ...
 - 7-9 旅游规划(25 分)(Dijkstra最短路径算法)
			
有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路径都是最短的,那么需要输出最便 ...
 - 【BZOJ4403】序列统计(Lucas定理,组合计数)
			
题意:给定三个正整数N.L和R, 统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量. 输出答案对10^6+3取模的结果. 对于100%的数据,1≤N,L,R≤10^9,1≤T≤100, ...
 - ACM组队安排-——杭电校赛(递推)
			
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...
 - c内存分配(转)
			
图示 C内存分配 程序代码区 存放函数体的二进制代码 全局数据区 全局变量和静态变量的存储是放在一起的.初始化的全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另一块区域. ...
 - 使用idea编译spring-framework5.0源码
			
自从迈入java开发这个行当,从来没有好好的研究过源码,深感惭愧,话不多说,今天上一篇使用idea编译spring5.0源码. 以下在win中构建和编译过程分为 jdk环境的配置 gradle的下载和 ...
 - Ubuntu 16.04下Redis Cluster集群搭建(官方原始方案)
			
前提:先安装好Redis,参考:http://www.cnblogs.com/EasonJim/p/7599941.html 说明:Redis Cluster集群模式可以做到动态增加节点和下线节点,使 ...
 - python中的is判断引用的对象是否一致,==判断值是否相等
			
python中的is判断引用的对象是否一致,==判断值是否相等 a = 10 b = 20 list = [1,2,3,4,5] print(a in list) print(b not in lis ...
 - [AngularJS] Store the entry url and redirect to entry url after Logged in
			
For example when a outside application need to visit your app address: https://www.example.com/#/lob ...
 - Mariadb    galera 集群
			
部署galera 多主架构 (galera集群多用于关键性业务,因为galera集群为了数据的一致性,采用的是同步的机制,这就使galera牺牲了一部分性能来换取数据一致性.) 环境准备:三台服务器 ...