【发布时间】:2020-02-20 02:56:58
【问题描述】:
我正在使用 Spring Boot 安全性:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
我已禁用 CSRF:
@Slf4j
@Configuration
public class AuthConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.csrf().disable();
}
}
使用npm start,我在我的 React 应用程序中运行以下代码:
axios
.post(this.state.targetUrl+'/mpbpm/triggerProcess', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS'
}
})
结果是:
Failed to load http://localhost:8080/mpbpm/triggerProcess: Response for preflight has invalid HTTP status code 401.
为什么失败了?我正在尝试学习 React,我有试图从服务器检索值的虚拟代码。最简单的方法是什么?
【问题讨论】:
标签: reactjs spring spring-security axios csrf