gpt4 book ai didi

java - Spring Rest-API - 403 禁止错误响应

转载 作者:行者123 更新时间:2023-11-30 08:08:37 25 4
gpt4 key购买 nike

我是 spring 的新手,我正在编写 REST API。我收到 403 forbidden error for delete, put。以下是我正在处理的示例。

@RequestMapping(value = "/{noteId}", method = RequestMethod.PUT)
public ResponseEntity noteIdPut(
@PathVariable("Id") String Id,
Note note)
throws Exception {
return service.updateNote(Id, note);
}

最佳答案

只需在 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>Content-Type,X-Requested-With,accept,authorization,Origin,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</param-value>
</init-param>
</filter>

关于java - Spring Rest-API - 403 禁止错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com