qiulingxin 2018-04-24 07:48 采纳率: 33.3%
浏览 7832
已结题

springboot 前后端分离使用shiro进行权限控制并使用cors进行跨域

springbootcookieshiro前端权限
springboot 前后端分离使用shiro进行权限控制并使用cors进行跨域
本来框架已经搭好了并且持续运行了一段时间前端已经能够拿到后台传过去的数据,cors配置

@Configuration
//@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("http://192.168.1.141:8080","http://127.0.0.1:8080")
            .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
            .allowCredentials(true).maxAge(3600);
}

/*private CorsConfiguration buildConfig(){
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedOrigin("http://192.168.1.141:8080");
    config.addAllowedOrigin("http://127.0.0.1:8080");
    config.addAllowedHeader("*");
    config.addAllowedMethod(HttpMethod.GET);
    config.addAllowedMethod(HttpMethod.POST);
    config.addAllowedMethod(HttpMethod.PUT);
    config.addAllowedMethod(HttpMethod.DELETE);
    config.addAllowedMethod(HttpMethod.OPTIONS);
    return config;
}

@Bean
public CorsFilter corsFilter(){
    UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
    configSource.registerCorsConfiguration("/**", buildConfig());
    return new CorsFilter(configSource);
}*/

}
但是今天前端请求菜单接口的时候报302问题(注:今天之前请求菜单接口是可以跨域返回数据的),不明觉厉,弄了很久还是没有弄好。

前端也加了

xhrFields: {
withCredentials: true
},
crossDomain: true,

  • 写回答

3条回答 默认 最新

  • 御赐 2018-04-24 08:16
    关注

    提供接口的服务器接收到你发送的请求,在返回结果时设置返回码为 302 ,你就会得到 302 。

    302 返回码代表暂时性转移,怎么处理要看你的具体需求。

    建议先了解HTTP协议

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥50 成都蓉城足球俱乐部小程序抢票