1

I keep getting this error when trying to use POST Method. I need to get from the API a list of certificates into a LIST, I know that "lista" is null right now, since I can´t get the API to bring me the lists yet.

public async Task<List<Certificaciones>> grillaCertificadosAsync(int id)
        {

        List<Certificaciones> lista = new List<Certificaciones>();
        var cert = new jsonCert()
        {
            idProyecto = id
        };

        var id1 = JsonConvert.SerializeObject(cert);
        var content = new StringContent(id1, Encoding.UTF8, "application/json");
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        var result = await client.PostAsync("https://certificacionesbuho.mendoza.gov.ar/api/BuhoBlanco/GetInfoCert", content);

        var responseBody = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
return lista;

This is the API.

        [Route("Api/BuhoBlanco/GetInfoCert")]
    [System.Web.Http.ActionName("GetInfoCert")]
    [System.Web.Http.HttpPost]
    public Respuesta GetInfoCert([FromBody]infoCertRequest infoCert)
    {
        Respuesta rta = new Respuesta();

        try
        {
            BuhoServicio.ServicioBuhoBlanco _servicio = new BuhoServicio.ServicioBuhoBlanco();
            rta.Exito = true;
            rta.StatusCode = HttpStatusCode.OK;
            rta.Data = _servicio.infoCertificados(infoCert.idProyecto);
            //((IDisposable)_servicio).Dispose();
            return rta;
        }
        catch (Exception ex)
        {
            rta.Error = ex.Message;
            rta.Exito = false;
            rta.StatusCode = HttpStatusCode.InternalServerError;
            return rta;
        }


    }
  • Does this fix your problem? [.net web API 405 verb not allowed](https://stackoverflow.com/questions/9854602/asp-net-web-api-405-http-verb-used-to-access-this-page-is-not-allowed-how/14465655#14465655). I ran into this issue recently and that fixed it for me – Rafalon Mar 07 '22 at 14:01
  • For starters, I would remove the public url (and only show the endpoint) because of obvious security reasons ;-) Perhaps your routeconfig has an error in it? – DaGrooveNL Mar 07 '22 at 16:17

1 Answers1

-1

IMHO route should be like this

    [HttpPost("~/Api/BuhoBlanco/GetInfoCert")]
    public Respuesta GetInfoCert([FromBody]infoCertRequest infoCert)
Serge
  • 40,935
  • 4
  • 18
  • 45