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

由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);  
            }  
        });  
      
    }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

longfulong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值