项目场景:
利用90版本之后的谷歌欣赏器, 在摆设前端项目后, 调用后端接口出现 strict-origin-when-cross-origin, 并且静态资源被拦截的环境
问题形貌:
利用90版本之后的谷歌欣赏器, 在摆设前端项目后, 访问前端页面调用后端接口出现 strict-origin-when-cross-origin.
接口返回200, 但是没有相应结果, 如下图所示

原因分析:
Chrome 计划在85版开始 将其切换默认计谋 no-referrer-when-downgrade 更换到 strict-origin-when-cross-origin. strict-origin-when-cross-origin对于同源的请求,会发送完备的URL作为引用地点;在划一安全级别的环境下,发送文件的源作为引用地点(HTTPS->HTTPS);在降级的环境下不发送此首部 (HTTPS->HTTP).
解决方案:
后端步伐设置全局跨域访问设置
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.CorsRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
- /**
- * @author
- *
- * 跨域访问配置
- */
- @Configuration
- public class WebMvcConfig implements WebMvcConfigurer {
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- .allowedOrigins("*")
- .allowCredentials(true)
- .allowedMethods("GET", "POST", "DELETE", "PUT")
- .maxAge(3600);
- }
- }
复制代码 来源:https://blog.csdn.net/qq_43371556/article/details/127848820
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |