一个应用程序在另一个应用程序中命中请求,但信息为空
One application hits a request in another but the information is empty
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}");
}
}
但 none 的信息已填充。我也尝试过使用 Postman,但无济于事。
你能给点建议吗?
已解决。将控制器中的方法更改为:
public async Task<IActionResult> ReceiveHardwareInfo([FromBody] HardwareInfoDto hardwareInfoDto)
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}");
}
}
但 none 的信息已填充。我也尝试过使用 Postman,但无济于事。
你能给点建议吗?
已解决。将控制器中的方法更改为:
public async Task<IActionResult> ReceiveHardwareInfo([FromBody] HardwareInfoDto hardwareInfoDto)