【发布时间】:2016-08-23 13:41:12
【问题描述】:
根据文档
http://docs.spring.io/autorepo/docs/spring/4.0.x/spring-framework-reference/html/mvc.html
有十六进制方法
@Controller
@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")
public void addPet(@RequestBody Pet pet, Model model) {
// implementation omitted
}
还有一个弹簧秒与下一个
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/pets").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}
通过POST插件发送请求,如
Content-Type: application/json
{"email":"test@gamil.com","pass":"testpass"}
有错误
**Status:
403: Forbidden**
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
怎么了?
【问题讨论】:
-
{"email":"test@gamil.com","pass":"testpass"}是否是用户凭据? -
根据spring security
antMatchers("/pets").permitAll()的规则我可以在没有用户凭证的情况下使用这个url。是吗? -
是的..但默认情况下,
CSRF Protection为POST请求启用。因此,您应该提供一个或禁用CSRF Protection。见stackoverflow.com/a/34703521/1393484
标签: json spring spring-mvc spring-security