httpsession跨域请求不能保存的问题

时间:2022-08-28 16:01:41

前端设置

$.ajaxSetup( {
xhrFields: {
withCredentials: true
}
} );
修改跨域请求携带cookie


后端修改

String origin = request.getHeader("Origin");
if(origin != null){
response.setHeader("Access-Control-Allow-Origin", origin);
}else{
response.setHeader("Access-Control-Allow-Origin", "*");
}
response.setHeader("Access-Control-Allow-Credentials","true");
修改后端请求允许跨域携带cookie

转载文章

http://harttle.com/2016/12/28/cors-with-cookie.html#3