Reputation: 85
I have an api that needs three parameters, a string(dataType),a class(eloanInput) and a bool(isCluster)
public HttpResponseMessage getEloanExcel(string dataType, EloanInput eloanInput, bool isCluster = false)
{
var exportDataService = new ExportDataService();
var exportExcel = new ExportExcel(dataType);
var inputParams = new CaseSearch.EloanInput();
inputParams.SEARCH_TYPE = eloanInput.SEARCH_TYPE;
inputParams.COUNTY_ID = eloanInput.COUNTY_ID;
inputParams.TOWN_ID = eloanInput.TOWN_ID;
inputParams.HOUSE_TYPES = (eloanInput.HOUSE_TYPES[0] == "-1" && eloanInput.HOUSE_TYPES.Count() == 1) ? null : eloanInput.HOUSE_TYPES;
inputParams.HouseProject = (eloanInput.HouseProject[0] == "-1" && eloanInput.HouseProject.Count() == 1) ? null : eloanInput.HouseProject;
inputParams.PUB_START_DT = eloanInput.PUB_START_DT;
inputParams.PUB_END_DT = eloanInput.PUB_END_DT;
}
just like the image below:
I have a problem when testing the API in Postman, I use key, value method to pass my parameters, and only eloanInput gets null, it doesn't get the values I passed to it, but other parameters indeed get the values by the postman.
[Key] [Value]
dataType 'Eloan'
eloanInput { "SEARCH_TYPE": 2,
"COUNTY_ID": "-1",
"TOWN_ID": "-1",
"PUB_START_DT": "2006/11/22",
"PUB_END_DT": "2006/12/15",
"HOUSE_TYPES": ["01", "02", "03"],
"HouseProject": [1, 2, 3, 4, 5],
"DONE_START_DT": "88",
"DONE_END_DT": "108",
"FLOOR_FROM": "1",
"FLOOR_TO": "18",
"BUILD_AREA_FROM": "2",
"BUILD_AREA_TO": "48",
"CASE_TYPE": [1, 2, 3, 4, 5],
"CASE_CATEGORY": [1, 2, 3, 4],
"CASENM_KEYWORD": "12"}
isCluster false
Postman Request:
Upvotes: 6
Views: 24606
Reputation: 10717
I would send that data from the request body (with the help of [FromBody]) and by changing it to [HttpPost]
method instead of [HttpGet]
.
Your updated method code:
[HttpPost]
public HttpResponseMessage getEloanExcel(string dataType, [FromBody] EloanInput eloanInput, bool isCluster = false)
{
// your code
}
and the request from Postman:
Upvotes: 7