location / {
if ($request_method ~* "(PUT|DELETE)") {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = { RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.OPTIONS })
@RestController
public class MyController {
// ...
}
通过以上两个步骤就可以解决 Spring Boot PUT 和 DELETE 请求返回 403 的问题了。