Chrome的插件CORS Toggle使用POST / PUT / DELETE方法无法正常工作

时间:2016-12-03 14:00:33

标签: javascript angularjs google-chrome cors crud

我已经解决了问题:No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access,这是CORS的一个问题,我解决了安装" CORS Toggle" Chrome插件,但它仅适用于GET方法。事实上,当我运行我的anguarjs http文件时,当我尝试使用其他方法(例如PUT)时,Chrome控制台会显示此错误:Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.。在我看来,该插件并没有获得所有CORS许可。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

删除插件。尝试在web.xml文件中添加以下行:

<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> <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,HEAD,OPTIONS,PUT,DELETE</param-value> </init-param> </filter> <filter-mapping>