繁体   English   中英

Spring不支持请求方法“POST”

[英]Request method 'POST' not supported with Spring

请原谅我的英语,默认情况下它不是我的语言。

我在一个项目中使用 Spring 和 SpringSecurity 来构建 API,并且从今天早上开始出现错误。

我的班级来构建服务

@RestController
@RequestMapping(value = {"/api/object" })
public class ObjectApiController {

    @RequestMapping(value = "/update", method = RequestMethod.POST)
        @ResponseBody
        public JsonResponse updateObject(@RequestBody BodyRequest bodyrequest) {
    // My code here
    }

我的班级 BodyRequest:

public class BodyTpe {
    private String arg1=null;
    private String arg2=null;

    public String getArg1() {
        return arg1;
    }
    public void setArg1(String arg1) {
        this.arg1= arg1;
    }
    public String getArg2() {
        return arg2;
    }
    public void setArg2(String arg2) {
        this.arg2= arg2;
    }

这是我对 Postman 的要求:

curl --location --request POST 'myaddress/api/object/update' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=xxxxxxxxxxxxxxxxx' \
--data-raw '{"arg1":"325-919-319",
"arg2":"116"}'

当我使用邮递员启动请求时,出现以下错误:

不支持请求方法“POST”

知道为什么它不起作用吗?

要使帖子生效,您需要使用 csrf。 因此,要么通过您的表单提供 csrf,要么禁用它。

将您的@RequestMapping注释更改为如下所示:

@RequestMapping("/api/object")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM