Это мой класс ApiTester:
Код: Выделить всё
[HttpGet]
public async Task ApiTester()
{
// Create an HTTP client instance
var client = _httpClientFactory.CreateClient();
// Send a POST request to the AuthController's ApiTest action
var response = await client.PostAsync("https://localhost:7108/api/auth/apitest", null);
if (response.IsSuccessStatusCode)
{
// Read the response content
var result = await response.Content.ReadAsStringAsync();
ViewBag.ApiResponse = result; // Store the result in ViewBag to display on the view
}
else
{
ViewBag.ApiResponse = "Error: " + response.StatusCode;
}
return View(); // Return the view with the response
}
Код: Выделить всё
[HttpPost("ApiTest")]
public IActionResult ApiTest()
{
return Ok(new { message = "200: test successful!" });
}

и в ответе var я получил это:

Полное сообщение запроса для var ответ:
Код: Выделить всё
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1,
Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Tue, 08 Oct 2024 05:55:19 GMT
Server: Kestrel
Transfer-Encoding: chunked
Content-Type: application/problem+json; charset=utf-8
}, Trailing Headers:
{
}}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ore-web-ap