在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  HTML/ Spring Boot如何允許所有域名都能跨域訪問并能使用credentials

Spring Boot如何允許所有域名都能跨域訪問并能使用credentials

使用@CrossOrigin(origins="*")時會有響應(yīng)頭Access-Control-Allow-Origin: *。這時前端設(shè)置withCredential 會報錯Failed to load http://localhost:8080/test: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access.
能否對所有的請求網(wǎng)站都設(shè)置對應(yīng)的響應(yīng)頭,如localhost:3000訪問就設(shè)置Access-Control-Allow-Origin: localhost:3000

回答
編輯回答
吢丕

被告知@CrossOrigin標(biāo)注無法實現(xiàn),可以通過過濾器Filter實現(xiàn)。
看了下Filter確實可以實現(xiàn),mdn有簡單的示例。

2017年7月14日 06:33