300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > axios.defaults.withCredentials跨域携带cookie

axios.defaults.withCredentials跨域携带cookie

时间:2019-07-18 15:45:20

相关推荐

axios.defaults.withCredentials跨域携带cookie

withCredentials:默认情况下,跨源请求不提供凭据(cookie、HTTP认证及客户端SSL证明等)。前端通过将withCredentials属性设置为true指定某个请求应该发送凭据

withCredentials默认值为false。true:在跨域请求时,会携带用户凭证false:在跨域请求时,不会携带用户凭证;返回的 response 里也会忽略 cookie

注意:当配置了 withCredentials = true时,必须后端配置增加 response 头信息Access-Control-Allow-Origin,且必须指定域名,而不能指定为*

如果后端需要带cookie过去,前端需要设置为true

// 服务端需要配置:// 响应头表示是否可以将对请求的响应暴露给页面Access-Control-Allow-Credentials: true// 允许跨域操作的具体域名Access-Control-Allow-Origin: "http://localhost:8080"// 允许跨域的HTTP方法Access-Control-Allow-Methods: ["GET","POST","DELETE"]// 列出将会在正式请求的 Access-Control-Expose-Headers 字段中出现的首部信息Access-Control-Allow-Headers: ["Content-Type", "Authorization", "Accept"]// 前端需要配置:// 表示跨域请求时是否需要使用凭证axios.defaults.withCredentials = true

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。