CORS跨域cookie传递

服务端

Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:*
Access-Control-Allow-Origin:http://a.xxx.com

客户端

1. jquery

复制代码
$.ajax({
    url: '...',
    type: 'get',
    xhrFields: {
        withCredentials: true
    },
    crossDomain: true,
    dataType: 'application/json; charset=utf-8'
});
复制代码

如果是http post,ajax的请求参数中contentType不能用applicaion/json,要用application/x-www-form-urlencoded

2. vue-resource

1、全局拦截器过滤

Vue.http.interceptors.push(function(request, next) {//拦截器
    // 跨域携带cookie
    request.credentials = true;
    next()
});

2、全局选项设置

Vue.http.options.xhr = { withCredentials: true }

3、单个请求设置

this.$http.get('xxxx',{params: {},credentials: true})
this.$http.jsonp('...', { credentials: true })

 

posted @   全玉  阅读(433)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示