Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 请求方法';邮政';不支持弹簧_Java_Spring_Api_Rest - Fatal编程技术网

Java 请求方法';邮政';不支持弹簧

Java 请求方法';邮政';不支持弹簧,java,spring,api,rest,Java,Spring,Api,Rest,请原谅我的英语,默认情况下它不是我的语言 我在一个项目中使用Spring和SpringSecurity来构建API,从今天早上开始就出现了一个错误 我的班级需要建立服务 @RestController @RequestMapping(value = {"/api/object" }) public class ObjectApiController { @RequestMapping(value = "/update", method = Req

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

我在一个项目中使用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
    }
我的班级要求:

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;
    }
这是我对邮递员的要求:

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”


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

要让post正常工作,您需要使用csrf。因此,可以通过表单提供csrf,也可以禁用它。

@RequestMapping
注释更改为如下内容:

@RequestMapping("/api/object")

与此问题相关的完整stacktrace将非常有助于对其进行分析。出现此问题的原因很多,因此需要完整的stacktrace。在控制器类所在的扫描包配置中,需要完整的stacktrace吗?谢谢,我这样做了,现在一切正常!