原创

Strophen跨域问题解决方法

原理:通过flash解决跨域的问题 (一)下载插件flXHR.js和strophe.flxhr.js',注意放的顺序
<script type="text/javascript" src='<%=basePath%>scripts/lib/strophe/flXHR.js'></script>
<script type="text/javascript" src='<%=basePath%>scripts/lib/strophe/strophe.js'></script>
<script type="text/javascript" src='<%=basePath%>scripts/lib/strophe/strophe.flxhr.js'>
</script>
(二)修改strophe.flxhr.js
将// xhr.onreadystatechange = this.func.prependArg(this);
替换成xhr.onreadystatechange = this.func.bind(null,this);
  (三)修改openfire代码,支持crossdomain  1找到文件HttpBindManager.java( org.jivesoftware.openfire.http),增加代码
context.addServlet(new ServletHolder(new FlashCrossDomainServlet()),"/crossdomain.xml");
  2在openfire_home/conf增加crossdomain.xml,文件内容
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy> 
<!--        Cross domain policy file for allow everything.  If you need more  information on these, please see:     http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html  --> 
<site-control permitted-cross-domain-policies="all"/> 
<allow-access-from domain="*" /> 
<allow-http-request-headers-from domain="*" headers="*" />
</cross-domain-policy>
正文到此结束
Loading...