繁体   English   中英

StatusCode:405,ReasonPhrase:使用 POST 方法时“方法不允许”

[英]StatusCode: 405, ReasonPhrase: 'Method Not Allowed' while using POST METHOD

我在尝试使用 POST 方法时不断收到此错误。 我需要从 API 中获取证书列表到 LIST 中,我知道“lista”现在是 null,因为我还不能获取 API 来给我列表。

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;

这是 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;
        }


    }

恕我直言路线应该是这样的

    [HttpPost("~/Api/BuhoBlanco/GetInfoCert")]
    public Respuesta GetInfoCert([FromBody]infoCertRequest infoCert)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM