[英]How to passing class object Postman
I have an api that needs three parameters, a string(dataType),a class(eloanInput) and a bool(isCluster)我有一个需要三个参数的 api,一个字符串(dataType),一个类(eloanInput)和一个 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.我在Postman中测试API时遇到问题,我使用key,value方法传递我的参数,只有eloanInput获取null,它没有获取我传递给它的值,但其他参数确实通过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:邮递员要求:
I would send that data from the request body (with the help of [FromBody]) and by changing it to [HttpPost]
method instead of [HttpGet]
.我会从请求正文发送该数据(在 [FromBody] 的帮助下)并将其更改为[HttpPost]
方法而不是[HttpGet]
。
Your updated method code:您更新的方法代码:
[HttpPost]
public HttpResponseMessage getEloanExcel(string dataType, [FromBody] EloanInput eloanInput, bool isCluster = false)
{
// your code
}
and the request from Postman:和邮递员的要求:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.