Excuse me for my english, it's not my language by default.
I use Spring and SpringSecurity in a project to build an API and I have an error since this morning.
My class to build the service
@RestController
@RequestMapping(value = {"/api/object" })
public class ObjectApiController {
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public JsonResponse updateObject(@RequestBody BodyRequest bodyrequest) {
// My code here
}
My class 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;
}
And this is my request on 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"}'
When I launch the request with postman, I have this error:
Request method 'POST' not supported
Any idea why it's not working ?
For post to work, you need to use csrf. So either supply a csrf via your form or disable it.
将您的@RequestMapping
注释更改为如下所示:
@RequestMapping("/api/object")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.