跨域项目
服务器端如果需要使用到session的时候,前端通过ajax访问服务器,需要在请求头headers中添加浏览器缓存的cookie信息
headers: {"Cookie": document.cookie}
结果会发现在ajax请求headers信息中,并没有设置的cookie信息
需要在设置cookie的时候,同时withCredentials设置为true
withCredentials: true,
headers: {"Cookie": document.cookie}
即可
angular4中,在http请求时添加cookie信息
let options = new RequestOptions({withCredentials: true});
this.http.get('', options).toPromise()