我正在开发一个RESTful Web服务项目,我正在使用Apache Tomcat和JAX-RS.
我想接受来自客户端的DELETE请求,但是当我从高级REST客户端Chrome插件发送DELETE请求时,它会提供响应代码403 Forbidden.
那么如何让Apche Tomcat接受DELETE请求?
解决方法
由于我的CORS过滤器,Tomcat阻塞了DELETE方法.
我需要在我的web.xml文件中注册新的过滤器.这是一个非常宽容的例子:
<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> <init-param> <param-name>cors.allowed.headers</param-name> <param-value>Accept,Accept-Encoding,Accept-Language,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization,Connection,Content-Type,Host,Origin,Referer,Token-Id,User-Agent,X-Requested-With</param-value> </init-param> <init-param> <param-name>cors.allowed.origins</param-name> <param-value>*</param-value> </init-param> <init-param> <param-name>cors.allowed.methods</param-name> <param-value>GET,POST,PUT,DELETE,OPTIONS,HEAD</param-value> </init-param> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>