首页 > 代码库 > 浏览器拦截跨域请求处理方法-firefox报错,同源策略不允许读取XXX上的远程资源
浏览器拦截跨域请求处理方法-firefox报错,同源策略不允许读取XXX上的远程资源
使用post请求域名不相同的资源的话,可以用cors跨域。
1) 在被请求的项目根目录(root下)下放以下文件
crossdomain.xml
- [html] view plaincopyprint?
- <?xml version="1.0"?>
- <!DOCTYPE cross-domain-policy SYSTEM "./cross-domain-policy.dtd">
- <cross-domain-policy> <site-control permitted-cross-domain-policies="all" />
- <allow-access-from domain="*" />
- <allow-http-request-headers-from domain="*" headers="*"/>
- </cross-domain-policy>
cross-domain-policy.dtd
[html] view plaincopyprint?
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <!-- Adobe DTD for cross-domain policy files -->
- <!-- Copyright (c) 2008-2009, Adobe Systems Inc. -->
- <!ELEMENT cross-domain-policy (site-control?,allow-access-from*,allow-http-request-headers-from*,allow-access-from-identity*)>
- <!ELEMENT site-control EMPTY>
- <!ATTLIST site-control permitted-cross-domain-policies (all|by-content-type|by-ftp-filename|master-only|none) #REQUIRED>
- <!ELEMENT allow-access-from EMPTY>
- <!ATTLIST allow-access-from domain CDATA #REQUIRED>
- <!ATTLIST allow-access-from to-ports CDATA #IMPLIED>
- <!ATTLIST allow-access-from secure (true|false) "true">
- <!ELEMENT allow-http-request-headers-from EMPTY>
- <!ATTLIST allow-http-request-headers-from domain CDATA #REQUIRED>
- <!ATTLIST allow-http-request-headers-from headers CDATA #REQUIRED>
- <!ATTLIST allow-http-request-headers-from secure (true|false) "true">
- <!ELEMENT allow-access-from-identity (signatory)>
- <!ELEMENT signatory (certificate)>
- <!ELEMENT certificate EMPTY>
- <!ATTLIST certificate fingerprint CDATA #REQUIRED>
- <!ATTLIST certificate fingerprint-algorithm CDATA #REQUIRED>
- <!-- End of file. -->
测试从http://domain:port/crossdomain.xml可访问到这两个xml。
2.)被请求的目标在返回时需加Responseheader Access-Control-Allow-Origin
response.setHeader("Access-Control-Allow-Origin", "*");
后面的*可以是请求方的域名。
参考:http://blog.csdn.net/hereiskxm/article/details/32093675
浏览器拦截跨域请求处理方法-firefox报错,同源策略不允许读取XXX上的远程资源
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。