Java 为什么post请求会导致禁止的错误?

Java 为什么post请求会导致禁止的错误?,java,spring-boot,postman,Java,Spring Boot,Postman,这是我的密码: 控制器: @PostMapping("/create") public ResponseEntity<?> createUser(@RequestBody UserExternalResource newUser) { try { LOGGER.info("Incoming request to create a user: {}", newUser); return userService.cr

这是我的密码:

控制器:

@PostMapping("/create")
    public ResponseEntity<?> createUser(@RequestBody UserExternalResource newUser) {
        try {
            LOGGER.info("Incoming request to create a user: {}", newUser);
            return userService.createUser(newUser);
        } catch (Exception e) {
            LOGGER.error("Error create user: " + newUser + ". Message: " + e.getMessage(), e);
            return new ResponseEntity<>(new ResponseResource("Error creating user!"), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
当我试图与邮递员一起发送此请求时,我收到403个禁止的错误

邮差控制台的回应:

POST /e/api/user/create
Content-Type: text/plain
cache-control: no-cache
Postman-Token: b6590554-b54e-4935-b0c2-bc43857b3dc1
User-Agent: PostmanRuntime/7.6.0
Accept: */*
Host: localhost:8500
cookie: EXAMPLE SERVICE-SESSIONID=3TWT113hsJ0e1LVQEDlQqp69O6U8VZx-7sFSyH63
accept-encoding: gzip, deflate
content-length: 284
{
 "user" : "John",
 "username" : "john1"
 }
HTTP/1.1 403
status: 403
Expires: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
X-XSS-Protection: 1; mode=block
Pragma: no-cache
Date: Wed, 06 Feb 2019 15:11:55 GMT
Connection: keep-alive
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
Content-Type: application/json;charset=UTF-8
{"timestamp":1549465915019,"status":403,"error":"Forbidden","message":"Access Denied","path":"/e/api/user/create"}
有人知道会有什么问题吗

{"timestamp":1549465915019,"status":403,"error":"Forbidden","message":"Access Denied","path":"/e/api/user/create"}
您将得到错误403。403的真正定义如下:

The 403 Forbidden error is an HTTP status code which means that accessing the page or resource you were trying to reach is absolutely forbidden for some reason.
您可能没有访问此方法的权限,因此会出现错误


如果您使用的是spring security,并且它正常工作,那么可能是因为CSRF,您可以通过在配置方法中执行以下操作来禁用它

http.csrf().disable();
您将得到错误403。403的真正定义如下:

The 403 Forbidden error is an HTTP status code which means that accessing the page or resource you were trying to reach is absolutely forbidden for some reason.
您可能没有访问此方法的权限,因此会出现错误


如果您使用的是spring security,并且它正常工作,那么可能是因为CSRF,您可以通过在配置方法中执行以下操作来禁用它

http.csrf().disable();

如果您使用的是spring安全,请尝试以下安全配置。
http.authorizeRequests().antMatchers(“//e/api/**”).permitAll()和().cors()和().csrf().disable()

如果您使用的是spring安全性,请尝试以下安全配置。
http.authorizeRequests().antMatchers(“/e/api/**”).permitAll()和().cors()和().csrf().disable()

使用Spring安全性?如果你有CORS保护,你可能需要在你的邮递员请求中包含一个来源标头。@Headlush我不使用Springsecurity@NicholasHirras我没有corsUsing Spring Security?如果你有CORS保护,你可能需要在你的postman请求中包含一个Origin头。@TheHeadlush我不使用Springsecurity@NicholasHirras我没有cors