Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
0


I have MVC architecture project.now i want to give api to android developer .so how can i test the POST API services through POSTMAN.when i send post service through postman it will return null value..

What I have tried:

<pre>url:-http://localhost/Master/AddEmployee

JSON DATA:- { "EmpFName":"Sa", "EmpMName":"s", "EmpLName":"SS", "AadhaarCardNumber":null, "PanCardNumber":null, "DateOfBirth":"1993-10-20T00:00:00", "Address":"Pune", "City":"Pune", "State":"Maharashtra", "Country":"India", "PinCode":"410505", "EmailID":"sa@GMAIL.COM", "Password":"123456", "PhotoPath":null, "MobileNo":"74487855545", "EmergancyContactNo":"7447774558", "MaritalStatus":"single", "Designation":"devlop", "ReportingMgr":1, "LeaveCount":18, "SpouseName":null, "SpDOB":null, "SpAge":null, "FirstChildName":null, "FCDOB":null, "FCAge":null, "SecondChidName":null, "SCDOB":null, "SCAge":null, "IsActive":true, "CreatedBy":null, "UpdatedOn":null, "Gender":"Female", "SCGender":"Male", "SpGender":"Female", "FCGender":"female"

}

cODE:-

[HttpPost] [Route("addemmployee")] public ActionResult AddEmployee( FormCollection form) { //employeedata empdata;

try
           {
           Employee emp = new Employee();

           emp.JoiningDate = Convert.ToDateTime(form["joining_date"]);
               emp.EmpFName = form["txt_fname"];
               emp.EmpMName = form["txt_mname"];
               emp.EmpLName = form["txt_lname"];
               emp.AadhaarCardNumber = form["aadhaarnum"];

             MasterReposities.SaveEmployee(emp);
Posted
Updated 16-Mar-19 11:46am
Comments
Afzaal Ahmad Zeeshan 15-Mar-19 9:12am    
You are uploading JSON data, and expecting to read form-body? I don't think that's going to happen.

One thing that you can do is, use the Request.Form property to read the values from the HTTP request. If not, then try to parse the JSON to an object and then read the property to see if that helps.

The properties enumerated in your JSON do not align with the form fields you are enumerating.

Have you tried this yet?
C#
[HttpPost]
[Route("addemmployee")]
public ActionResult AddEmployee(employeedata empdata) {
  emp.EmpFName = empdata.EmpFName;
  // and so on
 
Share this answer
 
Comments
Member 12227707 16-Mar-19 0:51am    
yes i try this but still it is not working..n how to JSON align with the form fields which are enumerating.
MadMyche 16-Mar-19 7:43am    
What is the method that you are using to make this request?
Member 12227707 18-Mar-19 1:36am    
There is mistake from my end..now it's working.Thank u.
MadMyche 18-Mar-19 6:54am    
Glad to hear you got it figured out
Ok. Based on what you have posted here. The post with JSON in the body using PostMan will not work. because the Action is expecting FormCollection object. Here how I post the form data using Postman.

1. In Postman, Click On the Body
2. Click on form-data
3. Enter the key value

You also can click on the Bulk Edit link to paste in the key value in a batch. Here a screenshot of the Postman

postman_form-data.PNG (17.9 KB)

postman_form-data_MVC.PNG (8.2 KB)
 
Share this answer
 
Comments
Member 12227707 18-Mar-19 1:36am    
it's working..thank u..but there is some values which are
divisiondetails.BranchId = LoggedInUser.BranchId;
divisiondetails.InstituteId = LoggedInUser.InstituteId;

after came debugger here it directly throw exception..how to pass these value through postman..
Bryian Tan 19-Mar-19 7:13am    
How LoggedInUser get populated?
Member 12227707 20-Mar-19 0:11am    
after login ..first authenticate then .

public ClientPortalIdentity LoggedInUser
{
get
{
return User.Identity as ClientPortalIdentity;
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900