本文共 798 字,大约阅读时间需要 2 分钟。
SpringBoot中配置了SSL之后,发现除了小程序访问后台的GET方法, 其余POST,DELETE都被拒绝,并且报错403.
找了好久原来是因为在Security的默认拦截器里,默认会开启CSRF处理,判断请求是否携带了token。
如果没有就拒绝访问。并且,在请求为
(GET|HEAD|TRACE|OPTIONS)
时,则不会开启。
既然是因为默认开启了CSRF,那关掉即可。可以加入以下代码关闭~
import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configuration@EnableWebSecuritypublic class SecurityConfigSEVEN extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //super.configure(http); http.csrf().disable(); //关闭CSRF }}
转载地址:http://zizci.baihongyu.com/