魔鬼不笑-_-
2021-04-17 14:27
采纳率: 100%
浏览 48

哪位大佬能帮我解决这个问题,我已经愁了好几天了

哪位大佬能帮我解决这个问题,我已经愁了好几天了
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 张小帅和刘美美 2021-04-17 15:06
    已采纳
    public class CrossInterceptor implements HandlerInterceptor {
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
            if (request.getHeader(HttpHeaders.ORIGIN) != null) {
                String origin = request.getHeader("Origin");
                response.addHeader("Access-Control-Allow-Origin", origin);
                response.addHeader("Access-Control-Allow-Credentials", "true");
                response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT,PATCH, HEAD");
                response.addHeader("Access-Control-Allow-Headers", "Content-Type");
                response.addHeader("Access-Control-Max-Age", "3600");
            }
            return true;
        }
    }

    先试试直接拦截处理

    点赞 1 评论

相关推荐 更多相似问题