Error 405 Method not allowed Asp.net web-api

Asked

Viewed 50 times

0

While trying to delete the record, I get this message, all other operations is working.

The code:

        //http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi/deletar/jogo/4512/5
        //http://localhost:7630/api/AspNetWebApi/deletar/jogo/4512/5
        //precisa usar o postman com opção delete formato json
        [HttpDelete]
        [Route("deletar/jogo/{nJogo}/{idusuario}")]
        public HttpResponseMessage Deletar(int nJogo, int idusuario)
        {
            try
            {
                var tTabela = new JogoDetalheAplicacao();
                var resultado = tTabela.Excluir(nJogo, idusuario);
                return Request.CreateResponse(HttpStatusCode.OK, resultado);
            }
            catch (Exception ex)
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }

In applying:

        public bool Excluir(int nJogo,  int idusuario)
        {
            var retorno = 0;
            var strQuery = string.Format("DELETE FROM TB_JOGO_DETALHE_TEMP WHERE NUMERO_JOGO = {0} AND IDUSUARIO = {1}; SELECT NUMERO_JOGO FROM TB_JOGO_DETALHE_TEMP WHERE NUMERO_JOGO = {0} AND IDUSUARIO = {1}", nJogo, idusuario);
            using (contexto = new Contexto())
            {
                var reader = contexto.ExecutaComandoComRetorno(strQuery);
                while (reader.Read())
                {
                    retorno = Convert.ToInt32(reader["NUMERO_JOGO"]);
                }
                reader.Close();
            }

            if (retorno == 0)
                return true;
            return false;
        }

http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi/deletar/jogo/4512/5

http://www.sistemaguardiao.com.br/webapi/api/AspNetWebApi/datahora/consulta

inserir a descrição da imagem aqui

  • Reading the first link you are trying to delete using the GET method. But it needs to show code node as you are doing.

  • @leopiazzoli, I’m using Delete, I posted the code is the address that can be tested, thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.