java cors delete_Java Spring REST API CORS不适用于通过jQuery与Chrome的DELETE请求

我正在创建一个使用jQuery编写的Web前端,它使用

Spring框架将REST请求发送到用

Java编写的REST Web服务.我在CORS请求中遇到了一个奇怪的错误.特别是,如果我使用Safari,一切正常;相反,使用Chrome,所有DELETE请求都失败(GET和POST请求在Chrome中也能正常工作).

我得到的错误是:

Response to preflight request doesn't pass access control check: No

'Access-Control-Allow-Origin' header is present on the requested

resource. Origin 'null' is therefore not allowed access.

The response had HTTP status code 403.

当Chrome发出第一个OPTIONS请求时会发生这种情况.

我关于CORS的代码是:

@Configuration

@EnableWebMvc

public class CorsConfigurator extends WebMvcConfigurerAdapter {

@Override

public void addCorsMappings(CorsRegistry registry) {

registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS");

}

}

@SpringBootApplication

public class App

{

public static void main( String[] args )

{

SpringApplication.run(App.class, args);

}

@Bean

public WebMvcConfigurer corsConfigurer() {

return new CorsConfigurator();

}

}

我还尝试将@CrossOrigin注释添加到我的@RestController,但没有任何改变.有人知道要解决这个问题吗?

谢谢,

马尔科

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值