gpt4 book ai didi

c# - 如何传递类对象 Postman

转载 作者:太空宇宙 更新时间:2023-11-03 12:01:32 25 4
gpt4 key购买 nike

我有一个需要三个参数的 api,一个字符串(数据类型)、一个类(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;
}

如下图所示:

webapi

我在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 请求:

postman api testing

最佳答案

我将从请求正文(在 [FromBody] 的帮助下)发送该数据,并将其更改为 [HttpPost] 方法而不是 [HttpGet]

您更新的方法代码:

[HttpPost]
public HttpResponseMessage getEloanExcel(string dataType, [FromBody] EloanInput eloanInput, bool isCluster = false)
{
// your code
}

以及 Postman 的请求:

enter image description here

关于c# - 如何传递类对象 Postman,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56823432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com