I have this error making a web app that gets info from an API, both made with ASP.NET Core MVC.
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Mon, 29 Apr 2024 07:42:05 GMT
Server: Kestrel
Transfer-Encoding: chunked
Content-Type: application/problem+json; charset=utf-8
}}
I have it in this part of the code, in the API Service class:
public async Task<bool> Guardar2(BACKUP_IPADS objeto2)
{
bool respuesta = false;
await Autenticar();
var cliente = new HttpClient();
cliente.BaseAddress = new Uri(_baseurl);
var content = new StringContent(JsonConvert.SerializeObject(objeto2), Encoding.UTF8, "application/json");
var response = await cliente.PostAsync("api/BACKUP_IPADS/Entregar_Ipad/", content);
if (response.IsSuccessStatusCode)
{
respuesta = true;
}
return respuesta;
}
it returns false
this is the part of the controller:
[HttpPost]
public async Task<IActionResult> Entregar(BACKUP_IPADS ob_backup)
{
bool respuesta;
respuesta = await _servicioAPI.Guardar2(ob_backup);
if (respuesta)
{
return RedirectToAction("Index2");
}
else
{
return NoContent();
}
}
this is the part of the button in the html:
<div style="margin-right: 4px;">
<form asp-action="Entregar" asp-controller="Home" method="post">
<button type="submit" class="btn btn-success btn-sm" style="border-radius: 5px;">Entregar</button>
</form>
</div>
New contributor
Marce is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.