[web教学] 解决 strict-origin-when-cross-origin 问题

[复制链接]
查看932 | 回复0 | 2023-8-23 11:51:05 | 显示全部楼层 |阅读模式 来自 中国北京
项目场景:

利用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).
  
解决方案:

   后端步伐设置全局跨域访问设置
  1. import org.springframework.context.annotation.Configuration;
  2. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  3. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  4. /**
  5. * @author
  6. *
  7. * 跨域访问配置
  8. */
  9. @Configuration
  10. public class WebMvcConfig implements WebMvcConfigurer {
  11.     @Override
  12.     public void addCorsMappings(CorsRegistry registry) {
  13.         registry.addMapping("/**")
  14.                 .allowedOrigins("*")
  15.                 .allowCredentials(true)
  16.                 .allowedMethods("GET", "POST", "DELETE", "PUT")
  17.                 .maxAge(3600);
  18.     }
  19. }
复制代码
来源:https://blog.csdn.net/qq_43371556/article/details/127848820
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则