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 })
上一篇:python操作Hbase


下一篇:Android菜鸟的成长笔记(6)——剖析源码学自定义主题Theme