-1

I would like to write web method(WebApi 2) as

GetArchiveDataForEngagements(collection of EngagementNumbers)

I have written code as

public async Task<IHttpActionResult> GetArchiveDataForEngagements(string[] 
        engagementNumber)
    {
        return Ok();
    }

and using postman ,My input is like below

{
    "engagementNumber":["one","two"]
}

I am getting "null" value for engagementNumber in web method.

Can anyone suggest , how can I achieve this?

Vishal Pawar
  • 356
  • 4
  • 12

2 Answers2

0

You cannot pass data to a GET method using values in a body.

You could pass values as multiple query string values like this:

https://example.com/controller/GetArchiveDataForEngagements?engagementNumber=one&engagementNumber=two

You have not given enough routing information to make an accurate guess at the URL, but the query string part is the important part.

Craig H
  • 2,001
  • 1
  • 14
  • 18
-1
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.