日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

cookies丢失 同域名_后端设置Cookie前端跨域获取丢失问题(基于springboot实现)

發布時間:2023/12/3 HTML 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cookies丢失 同域名_后端设置Cookie前端跨域获取丢失问题(基于springboot实现) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.跨域問題說明:后端域名為A.abc.com,前端域名為B.abc.com。

2.后端設置一個cookie發送給前臺,domain應該是setDomain(“abc.com”),而不是setDomain(“B.abc.com”)

3.另外,還要實現WebMvcConfigurerr配置加入Cors的跨域

@Configurationpublic classWebConfig implements WebMvcConfigurer {

@Overridepublic voidaddCorsMappings(CorsRegistry registry) {

registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "OPTIONS", "PUT")

.allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method","Access-Control-Request-Headers")

.exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")

.allowCredentials(true).maxAge(3600);

}

}

--------------------------------------------分割線2018-9-16--------------------------------

由于之前的項目要搬到springcloud上面,所有就有了zuul網關來管理所有的請求,之前cookie設置的請求頭Authoriaztion居然沒有被傳到前端。

涼涼……

設置網關層跨域問題都已經全部允許任何請求頭(下圖),但是還是前端訪問還是沒有Authoriaztion,各種問題都排查了,都沒有問題。。。大寫的迷惘!!!

后來啊,干脆把Authoriaztion名字給改了,直接改為token。

艸,居然可以了,前端能拿到token;改回Authoriaztion,沒有。。。

后來查了資料,才發現哦,zuul會默認過濾掉幾個敏感詞,沒錯,就是它:

/**

* List of sensitive headers that are not passed to downstream requests. Defaults to a

* "safe" set of headers that commonly contain user credentials. It's OK to remove

* those from the list if the downstream service is part of the same system as the

* proxy, so they are sharing authentication data. If using a physical URL outside

* your own domain, then generally it would be a bad idea to leak user credentials.

*/

private Set sensitiveHeaders = new LinkedHashSet<>(

Arrays.asList("Cookie", "Set-Cookie", "Authorization"));

而我,剛好就中獎了!!!

總結

以上是生活随笔為你收集整理的cookies丢失 同域名_后端设置Cookie前端跨域获取丢失问题(基于springboot实现)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。