码迷,mamicode.com
首页 > 数据库 > 详细

Method PUT is not allowed by Access-Control-Allow-Methods in preflight response

时间:2020-06-29 20:09:38      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:问题   head   not   div   post   throws   col   lazy   ade   

  前端通过XHR请求后端服务时,出现了下图现象:

技术图片

  根据问题的描述可知,是遇到跨域问题了,为了支持跨域,需要在后端做一下处理,可以这样处理:

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT, OPTIONS");
        filterChain.doFilter(servletRequest, servletResponse);
    }

  具体的添加过程,可以参考此链接

  https://www.cnblogs.com/bien94/p/13188699.html

Method PUT is not allowed by Access-Control-Allow-Methods in preflight response

标签:问题   head   not   div   post   throws   col   lazy   ade   

原文地址:https://www.cnblogs.com/bien94/p/13209865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!