您的位置:首页 > 其它

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

2017-02-21 10:27 218 查看
由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);
}
});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: