Spring boot: Request method 'PUT' not supported

前端 未结 5 1624
傲寒
傲寒 2021-01-07 06:12

I am getting a Request method \'PUT\' not supported error on hitting a PUT method on a restful API to upload a file.

Following is the

5条回答
  •  借酒劲吻你
    2021-01-07 06:40

    To enable the PUT verb you have to add an interceptor that allows that method in the response header.

    Something like that:

    public class SasAllowOriginInterceptor extends HandlerInterceptorAdapter {
    
      @Override
      public boolean preHandle(HttpServletRequest request,
                               HttpServletResponse response, Object handler)
        throws Exception {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods",
                           "GET, POST, PUT, DELETE, OPTIONS");
        return true;
      }
    }
    

    I don't know how to add an interceptor using spring boot though, and I would be intersted in knowing it :)

提交回复
热议问题