Java – how to make Apache Tomcat accept the delete method
•
Java
I'm developing a restful web services project. I'm using Apache Tomcat and jax-rs
I want to accept the delete request from the client, but when I send the delete request from the advanced rest client chrome plug-in, it will provide the response code 403 Forbidden
So how to make Apache Tomcat accept the delete request?
Solution
Tomcat blocked the delete method due to my CORS filter
I need it on my web Register a new filter in the XML file This is a very tolerant example:
<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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码