【问题标题】:WARN : org.springframework.web.servlet.PageNotFound - Request method 'POST' not supported警告:org.springframework.web.servlet.PageNotFound - 不支持请求方法“POST”
【发布时间】:2019-07-31 12:32:51
【问题描述】:

我有一个带有 POST 和 GET 请求的简单控制器

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class UserRegistrationController {

    @RequestMapping(value="/register", method=RequestMethod.GET)
    public String showForm() {

        System.out.println("*****************************************");
        System.out.println("*****************************************");
        System.out.println("**** UserRegistrationController  GET    ****");
        System.out.println("*****************************************");
        System.out.println("*****************************************");
        return "register";
    }

    @RequestMapping(value="/registerNewUser", method=RequestMethod.POST)
    public String registerNewUser() {

        System.out.println("*****************************************");
        System.out.println("*****************************************");
        System.out.println("**** UserRegistrationController POST    ****");
        System.out.println("*****************************************");
        System.out.println("*****************************************");
        return "register";
    }
}

我用邮递员打电话。后端点不起作用。我得到: 警告:org.springframework.web.servlet.PageNotFound - 不支持请求方法“POST”

这是邮递员的卷曲

curl -X POST \
  http://localhost:28080/auther/registerNewUser \
  -H 'Postman-Token: 6bb6ef17-1baf-423e-bbec-15713468ff09' \
  -H 'cache-control: no-cache'

我是否需要配置一些东西来允许向这个控制器发送请求?

【问题讨论】:

    标签: spring-mvc post


    【解决方案1】:

    解决了。如果没有 csrf 令牌,它将无法与 Curl 一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2014-02-11
      • 2016-11-11
      • 2013-04-12
      • 1970-01-01
      • 2019-05-07
      相关资源
      最近更新 更多