加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FLEX跨域远程访问

发布时间:2020-12-15 04:55:07 所属栏目:百科 来源:网络整理
导读:?? 整这个玩意,整了好久,原因:策略文件必须放在远程服务器的根目录下。像网上说的在flex的主应用中写入 Security.loadPolicyFile("http:// localhost:8080/direc/crossdomain.xml");来设置访问的路径,,?? 我勒个去,,完全是忽悠人的,,? 整了咱一早上

?? 整这个玩意,整了好久,原因:策略文件必须放在远程服务器的根目录下。像网上说的在flex的主应用中写入 Security.loadPolicyFile("http:// localhost:8080/direc/crossdomain.xml");来设置访问的路径,,?? 我勒个去,,完全是忽悠人的,,? 整了咱一早上,,好吧,下午在官网上硬着头皮看着英文发现了一句话,原话就不写了,大概意思 :flex始终会在对方服务器上的根目录来查找主策略文件,用Security.loadPolicyFile只是用来找到从策略文件。

? 好吧那就把策略文件丢在服务器的根目录上呗,,结果在强大的ESB/MULE中, 端口号又是一个大问题,,有待研究,,,结果没办法,只能折中一下,用java了·······

?? 废话说了一大堆,上代码:

java端:

?

 
 
  1. package?com.zjht.call;?
  2. ?
  3. import?java.io.BufferedInputStream;?
  4. import?java.io.PrintWriter;?
  5. import?java.net.HttpURLConnection;?
  6. import?java.net.SocketTimeoutException;?
  7. import?java.net.URL;?
  8. ?
  9. import?javax.servlet.http.HttpServletRequest;?
  10. import?javax.servlet.http.HttpServletResponse;?
  11. ?
  12. import?org.apache.log4j.Logger;?
  13. import?org.springframework.stereotype.Controller;?
  14. import?org.springframework.web.bind.annotation.RequestMapping;?
  15. import?org.springframework.web.bind.annotation.RequestMethod;?
  16. ?
  17. import?com.zjht.hrm.action.AttachmentDownloadAction;?
  18. ?
  19. @Controller?
  20. public?class?CrossdomainAction?{?
  21. ????private?static?Logger?log?=?Logger.getLogger(AttachmentDownloadAction.class.getClass());?
  22. ?????
  23. ????@RequestMapping(value?=?"crossdomain",?method?=?{?RequestMethod.POST,?RequestMethod.GET?})?
  24. ????public?void?crossdomain(String?url,?final?HttpServletRequest?request,?final?HttpServletResponse?response)?throws?Exception?{?
  25. ????????response.setCharacterEncoding("UTF-8");?
  26. ????????response.setContentType("text/xml");?
  27. ? PrintWriter?out?=?response.getWriter();?
  28. ????????try?{?
  29. ????????????out.println(details);?
  30. ????????}?catch?(Exception?e)?{?
  31. ????????????log.error("response.sendError?Exception:",e);?
  32. ????????????throw?new?Exception("数据加载失败请联系研发部:"?+?e.getMessage());?
  33. ????????}finally{?
  34. ????????????out.flush();?
  35. ????????????out.close();?
  36. ????????}?
  37. ?
  38. ????}?
  39. ?
  40. ????public?String?GetRemoteDetails(String?urlStr)?throws?Exception?{?
  41. ????????String?s?=?"";?
  42. ????????StringBuffer?sb=new?StringBuffer();?
  43. ????????try?{?
  44. ????????????URL?url?=?new?URL(urlStr);?
  45. ????????????HttpURLConnection?connection?=?(HttpURLConnection)?url.openConnection();?
  46. ????????????connection.setConnectTimeout(30000);?
  47. ????????????connection.setReadTimeout(30000);?
  48. ????????????connection.connect();?
  49. ????????????BufferedInputStream?bis?=?new?BufferedInputStream(connection.getInputStream());?
  50. ????????????int?c;?
  51. ????????????while?((c?=?bis.read())?!=?-1)?{?
  52. ????????????????sb.append((char)c);?
  53. ????????????}?
  54. ????????????s=?new?String(sb.toString().getBytes("iso8859-1"),?"utf-8");?
  55. ????????}catch?(SocketTimeoutException?e)??
  56. ????????{?
  57. ????????????log.error("连接超时:",e);?
  58. ????????????throw?new?Exception("连接超时请联系研发部:"?+?e.getMessage());?
  59. ????????}catch?(Exception?e)?{?
  60. ????????????log.error("数据加载失败:",e);?
  61. ????????????throw?new?Exception("数据加载失败请联系研发部:"?+?e.getMessage());?
  62. ????????}?
  63. ????????return?s;?
  64. ????}?
  65. ?????
  66. }?

Flex端:

?

 
 
  1. <s:HTTPService?id="loader"?url="/ChinaExpress/crossdomain.do"??resultFormat="e4x"??method="GET"?useProxy="false"/>?
  2. ?
  3. ????loader.addEventListener(ResultEvent.RESULT,ticketInfoList);?
  4. ????????????????params?=?new?URLVariables();?
  5. ?
  6. params.url="URL"?
  7. loader.send(params);?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读