How to send post request with spring @RequestBody in rest client
I have a class Person.
class Person{
Integer id;
String firstName;
String lastName;
//other params, constructors, getters & setters
}
& My method is
@RequestMapping(value = "/test", method = RequestMethod.POST)
public void testPerson(
@RequestBody Person person){
...
}
Now I need to test it using rest client. I tried setting up “request header” section of the Firefox plugin to have a “name” = “Content-Type” and “value” = “application/x-www-form-urlencoded” & then add parameters in body,
id=1&firstName=aaa&lastName=bbb
but it's giving 404.
If you are getting 404
response, this means either your request URL is wrong or you using GET
method instead of POST
or vise versa.
Then regarding passing Person
in request, if @RequestBody
is used you have to pass JSON or XML in the body of the request as playload.
JSON:
{
"id":1,
"firstName":"aaa",
"lastName":bbb
}
XML
<person>
<id>1<id>
<firstName>aaa</firstName>
<lastName>bbb</lastName>
</person>
链接地址: http://www.djcxy.com/p/8628.html