首页 > 学院 > 开发设计 > 正文

sso中子系统之间用post方式通信

2019-11-08 01:26:05
字体:
来源:转载
供稿:网友

由A和B两个系统组成的sso站点中,A系统的网址为http://a.domin.com:8899,B系统的网址为http://b.domin.com:9876.

//B系统后台的test方法    public void test(HttpServletRequest request,HttpServletResponse response) throws Exception    {        //String data = (String) request.getParameter("data");//取参数        //业务处理略        response.setContentType("application/json; charset=UTF-8");        response.setHeader("access-Control-Allow-Origin", "http://b.domin.com:9876");//如果有端口必须加上        response.setHeader("Access-Control-Allow-Credentials", "true");        response.setHeader("Access-Control-Allow-Methods", "GET,POST");        response.setHeader("Access-Control-Allow-Headers",                "Content-Type, Content-Range, Content-Disposition, Content-Description");        response.getWriter().write("{/"state/":1,/"msg/":/"ok/"}");        return;    }        //A系统页面部分调用B系统的test方法可以用如下代码:    function test(){                  var contentType ="application/x-www-form-urlencoded; charset=utf-8";          if(window.XDomainRequest){//for IE8,IE9              contentType = "text/plain";          }           $.Ajax({                  url : "test",//test方法的访问路径              data:{id:1,age:22},              type : "POST",              dataType : "json",              xhrFields: {                    withCredentials: true                 },              crossDomain: true,              contentType:contentType,              success : function(data) {                  alert(data.state);              },              error : function(data){                  alert(2);              }          });            }


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表