WEB API 2 works on the localhost but not on the server

Asked

Viewed 743 times

0

I’m starting with .NET Web Api 2 using .Net Core.

In the Postman when I make the request on the localhost of my Webapi machine returns me a status 200 ok, but when I do on the server with the same Webapi returns me 403 method not allowed (the server is already set up right, with the ports released and running the Post normally).

GET

http://localhost:35056/api/listar (returns 200 OK and the list of users) http://10.0.0.9:8080/api/list (returns 200 OK and the list of users)

PUT

http://localhost:35056/api/client/update/477 (returns 200 OK) http://10.0.0.9:8080/api/client/update/477 (returns 405 method not allowed)

Clientecontroller: [Httpput]

    [Route("atualizar/{id}")]

    public ReturnAllServices Atualizar(int id, [FromBody]ClienteModel dados)

    {

        ReturnAllServices retorno = new ReturnAllServices();



        try

        {

            dados.Id = id;

            dados.AtualizarCliente();

            retorno.Result = true;

            retorno.ErrorMessage = string.Empty;



        }

        catch (Exception ex)

        {

            retorno.Result = false;

            retorno.ErrorMessage = "Erro ao registrar cliente" + ex.Message;

        }



        return retorno;





    }

// Clientemodel Update.

public void Updater()

    {

        Conn objConn = new Conn();

        string sql = "UPDATE cliente SET Nome=@nome WHERE id=@id";

        MySqlCommand cmd = new MySqlCommand();



        cmd.CommandText = sql;

        cmd.Parameters.AddWithValue("@nome", Nome);

        cmd.Parameters.AddWithValue("@id", Id);



        objConn.ExecutaQuery(cmd);





    }

returns me the following message in Postman:

405 - The HTTP verb used to access this page is not permitted.

The page you are looking for cannot be displayed as it was used an invalid method (HTTP verb) to try the access.

Note: I am not using Token because it is a web api on local server with access on local machines only, the post is working normally..

  • Can put the application code that is starting the request?

  • The request is being made Put via Postman, I have no client application that consumes yet..

  • @Lucas Where is the application hosted? You have access to the IIS configuration panel?

  • @LINQ is hosted on a local server with Windows Server 2012 R2.. have yes, in case I added on web.config the following config : <system.webserver> <modules runAllManagedModulesForAllRequests="false"> <remove name="Webdavmodule" /> </modules> </system.webserver>

  • @LINQ and solved, Webdav is Enabled on the server, in fact I do not even know what it is for, if disable or remove it I will have problems? I read on a website that webdav disables put and delete by default, so it was running on the normal localhost and the server environment was giving error 405..

No answers

Browser other questions tagged

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