【发布时间】:2021-01-18 01:54:51
【问题描述】:
public async Task Execute(IJobExecutionContext context)
{
var result = this.hardwareInfoManager.GetHardWareInfo();
Log.Logger.Information(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.Information(response.StatusCode.ToString());
if (response.Content != null)
{
Log.Logger.Information(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,但无济于事。
你能建议吗?
【问题讨论】:
-
这里只是走弯路,如果你把
ReceiveHardwareInfo(HardwareInfoDto hardwareInfoDto)改成ReceiveHardwareInfo(object hardwareInfoDto)会怎么样 -
不幸的是还是空的
-
如果您删除
[Route("/api/v1/healthmonitor")]标记并点击该端点会怎样?
标签: c# asp.net-core httprequest response