第一季

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

问题场景, 用js访问其他web资源,会出现跨域访问安全限制错误。

 

方案一:

参见文章: https://developer.mozilla.org/en/http_access_control

The summary is that

send extra header like

  1. Origin: http://foo.example  
  2. Access-Control-Request-Method: POST  

Origin is needed

Access-Control-Request-Method is needed only when POST is used

Access-Control-Request-Headers: X-PINGOTHER is needed when having special header (like X-PINGOTHER)

 

server can response with

Access-Control-Allow-Origin: *

that allow the response accepted by pages from other site

 

方案二:

让本地应用程序提供一个接口去做这个链接请求, 即通过后台程序完成。

 

方案三:flash 脚本

url_.text = "http://www.google.com/ig/api?hl=en-US&weather=,,,39904214,116407413";
send_BT.addEventListener(MouseEvent.CLICK,send_);
function send_(evt:Event){
var ld:URLLoader = new URLLoader();
ld.load(new URLRequest(url_.text));
ld.addEventListener(Event.COMPLETE, urlLoader_complete);
}
function urlLoader_complete(evt:Event){
log_.text = evt.target.data;
}

 

posted on 2012-06-05 18:59  第一季  阅读(291)  评论(0编辑  收藏  举报