Web services 如何使用列表输入编写web api Get方法
我想将web方法(WebApi 2)编写为 GetArchiveDataForEngagements(业务编号的集合) 我已经编写了如下代码Web services 如何使用列表输入编写web api Get方法,web-services,asp.net-web-api,c#-4.0,asp.net-web-api2,Web Services,Asp.net Web Api,C# 4.0,Asp.net Web Api2,我想将web方法(WebApi 2)编写为 GetArchiveDataForEngagements(业务编号的集合) 我已经编写了如下代码 public async Task<IHttpActionResult> GetArchiveDataForEngagements(string[] engagementNumber) { return Ok(); } 我在web方法中获取engagementNumber的“null”值 有人
public async Task<IHttpActionResult> GetArchiveDataForEngagements(string[]
engagementNumber)
{
return Ok();
}
我在web方法中获取engagementNumber的“null”值
有人能建议我如何实现这一点吗?不能使用主体中的值将数据传递给GET方法 可以将值作为多个查询字符串值传递,如下所示:
https://example.com/controller/GetArchiveDataForEngagements?engagementNumber=one&engagementNumber=two
您没有提供足够的路由信息来准确猜测URL,但查询字符串部分是重要部分。公共类测试
public class TEST
{
public string[] engagementNumber { get; set; }
}
[HttpPost]
[Route("test")]
public async Task<IHttpActionResult> GetArchiveDataForEngagements(TEST t)
{
return Ok();
}
Postman URL:
http:/localhost:8888/api/testCon/test
Postman Body: JSON(application/json)
{
"engagementNumber":["one","two"]
}
TestCon is the name of the controller.
{
公共字符串[]约定编号{get;set;}
}
[HttpPost]
[路线(“测试”)]
公共异步任务GetArchiveDataForEngagements(测试t)
{
返回Ok();
}
邮递员网址:
http:/localhost:8888/api/testCon/test
邮递员正文:JSON(应用程序/JSON)
{
“约定编号”:[“一”、“二”]
}
TestCon是控制器的名称。
您是否正在发布?您可能需要添加FromBody属性
public class TEST
{
public string[] engagementNumber { get; set; }
}
[HttpPost]
[Route("test")]
public async Task<IHttpActionResult> GetArchiveDataForEngagements(TEST t)
{
return Ok();
}
Postman URL:
http:/localhost:8888/api/testCon/test
Postman Body: JSON(application/json)
{
"engagementNumber":["one","two"]
}
TestCon is the name of the controller.