Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post object and List using postman

Tags:

I am using postman packaged app to send a post request.

I want to request the following controller.

How to send a post requestbody using postman object(with values) and a list using the raw format?

    @RequestMapping(value = "register", method = RequestMethod.POST)     @ResponseBody     public ResponseMessage save(@RequestBody Freelancer freelancer, @RequestBody List<Integer> skills) { 

I have tried like this :

{   "address": "colombo",   "username": "hesh",   "password": "123",   "registetedDate": "2015-4-3",   "firstname": "hesh",   "contactNo": "07762",   "accountNo": "16161",   "lastName": "jay" } {     "array[0]" :1436517454492,     "array[1]" :1436517476993 } 
like image 402
heshjse Avatar asked Jul 10 '15 09:07

heshjse


People also ask

How pass JSON object in POST request in Postman?

In Postman, change the method next to the URL to 'POST', and under the 'Body' tab choose the 'raw' radio button and then 'JSON (application/json)' from the drop down. You can now type in the JSON you want to send along with the POST request. If this is successful, you should see the new data in your 'db. json' file.


2 Answers

Make sure that you have made the content-type as application/json in header request and Post from body under the raw tab.

{   "address": "colombo",   "username": "hesh",   "password": "123",   "registetedDate": "2015-4-3",   "firstname": "hesh",   "contactNo": "07762",   "accountNo": "16161",   "lastName": "jay",   "arrayObjectName" : [{     "Id" : 1,     "Name": "ABC" },     {     "Id" : 2,     "Name" : "XYZ"   }],   "intArrayName" : [111,222,333],   "stringArrayName" : ["a","b","c"]   } 
like image 70
Mohsin Muzawar Avatar answered Sep 19 '22 20:09

Mohsin Muzawar


I also had a similar question, sharing the below example if it helps.

My Controller:

@RequestMapping(value = {"/batchDeleteIndex"}, method = RequestMethod.POST) @ResponseBody public BaseResponse batchDeleteIndex(@RequestBody List<String> datasetQnames) 

Postman: Set the Body type to raw and add header Content-Type: application/json

["aaa","bbb","ccc"] 
like image 40
user10784930 Avatar answered Sep 21 '22 20:09

user10784930