Spring Cloud发送POST请求时提示403
0
引入了spring-boot-starter-security依赖后,配置了通过所有请求,GET请求正常,但是POST请求被拦截,提示403。
这时需要添加.csrf().disable()这段代码,来禁用csrf拦截:
@Override
protected void configure(HttpSecurity security) throws Exception {
security
.csrf().disable() // 解决POST请求403错误
.authorizeRequests()
// .requestMatchers(EndpointRequest.toAnyEndpoint()).denyAll()
// .requestMatchers(EndpointRequest.toAnyEndpoint()).access("hasIpAddress('0:0::/112') or hasIpAddress('192.168.1.0/24')")
// .antMatchers("/actuator/**").denyAll()
// .antMatchers("/actuator/**").access("hasIpAddress('0:0::/112') or hasIpAddress('192.168.1.0/24')")
.anyRequest().permitAll(); // 允许
}