I am trying to call one of my APIs POST method from my client code using httpclient. The problem is that I want to pass array of integer(ids) as request body as per my destination APIs POST method, but I am not able to call this method using my source code.
Could anyone help me ?
Destination code:
public IActionResult GetByIds([FromBody] int[] ids)
{
try
{
var collterals = _collateralRepository.GetCollateralsByIds(ids);
return Ok(collterals);
}
catch (Exception)
{
throw;
}
}
Source Code:
int[] ids = outputsummary.Select(x => x.Collateral_Id).ToArray();
var data = new StringContent(JsonConvert.SerializeObject(ids), Encoding.UTF8, "application/json");
var collateralClient = _httpClientFactory.CreateClient("CollateralClient");
var response = await collateralClient.PostAsync("Collateral/GetByIds", data);
catch (Exception) { throw; }well, that doesn't add any value...