CORS方法PATCH未显示在访问控制允许方法中



我正在开发angular 9应用程序,并使用angular httpclient发送补丁需求。但由于飞行前请求未通过,require总是失败。我知道我可以添加一些关于allow方法的设置,我确实添加了,但仍然不起作用,似乎我的设置不适用于angular httpclient。我已经在这个问题上停留了很长时间,请给我一些建议。服务器是Tomcat7(7.0.106(,rest api是jersery,这里是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.headers</param-name>
<param-value>Authorization,Content-Type,X-Requested-With,Origin,Accept,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH</param-value>
</init-param>
</filter>

以下是angular httpclient(失败的一个(在Chrome中的请求详细信息

**General**
Request URL: http://localhost:8080/api/v1/user/testPatch
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: [::1]:8080
Referrer Policy: strict-origin-when-cross-origin
**Request Header**
...
Accept: */*
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: PATCH
Cache-Control: no-cache
Connection: keep-alive
Host: localhost:8080
Origin: http://localhost:4200
Pragma: no-cache
Referer: http://localhost:4200/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
...
**Response Header**
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization,Content-Type,X-Requested-With,Origin,Accept,Access-Control-Request-Method,Access-Control-Request-Headers
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD, OPTIONS
Access-Control-Allow-Origin: http://localhost:4200
Allow: OPTIONS,PATCH
Content-Length: 803
Content-Type: application/vnd.sun.wadl+xml
Server: HTTP Server
...

正如你所看到的,PATCH方法不在";访问控制允许方法";,但我已经在web.xml中设置了它,我不知道我缺少了什么。顺便说一句,我可以通过Postman成功调用同一个api;访问控制允许方法";响应中的设置与我在web.xml 中设置的完全相同

我终于找到了问题,但首先感谢@Andrei和@Paul Samsotha的回复。这个问题的原因是我使用了一个Chrome cors插件,该插件将使cors请求的allow方法失效,并且alllow方法的默认值不包括"PATCH";。

最新更新