问题描述
public async Task Execute(IJobExecutionContext context)
{
var result = this.hardwareInfoManager.GetHardWareInfo();
Log.Logger.@R_190_4045@ion(JsonConvert.SerializeObject(result));
using (HttpClient client = new HttpClient())
{
var url = Configuration.GetValue<string>("HealthMonitorApplicationUrl");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,url);
var serializedString = JsonConvert.SerializeObject(result);
request.Content = new StringContent(serializedString,Encoding.UTF8,"application/json");
var response = await retryPolicy.ExecuteAsync(async () => await client.PostAsync(url,request.Content));
if (response.StatusCode != HttpStatusCode.OK)
{
Log.Logger.@R_190_4045@ion(response.StatusCode.ToString());
if (response.Content != null)
{
Log.Logger.@R_190_4045@ion(await response.Content.ReadAsstringAsync());
}
}
}
}
我向url“ http:// localhost:5002 / api / v1 / healthmonitor”发送了一个请求。
[Route("/api/v1/healthmonitor")]
[HttpPost]
public async Task<IActionResult> ReceiveHardwareInfo(HardwareInfoDto hardwareInfoDto)
{
var result = await hardwareInfoManager.SaveHardwareInfo(hardwareInfoDto);
if (result.Succeeded)
{
return Ok(result);
}
else
{
return BadRequest($"{result.Errors}");
}
}
但是没有任何信息被填充。我也尝试使用Postman,但无济于事。
你能建议吗?
解决方法
已解决。将控制器中的方法更改为此:
public async Task<IActionResult> ReceiveHardwareInfo([FromBody] HardwareInfoDto hardwareInfoDto)