HTTP Status 405 - Method Not Allowed Error on Invoking a DELETE method using WebServices

20,883

Solution 1

URL = /contacts/delete/contactname

405 because

It seems delete is always behave as submit (Post method) and you are trying to call as like get method from the URL. This is not possible to call the post method as like get. if you really want to call this web service from the browser to test, just download a Mozilla plugin (Poster) which will help you to submit the web service in your all method types.

Solution 2

If you are using Firefox use this plugin to test your service. When you directly hit the URL from browser it goes as a @GET request which is not allowed in this case. RestClient is also available as standalone app. If you need more functionalities try SoapUI. I have also posted a response to your question on @DELETE.

Share:
20,883
Chillax
Author by

Chillax

Updated on October 02, 2020

Comments

  • Chillax
    Chillax over 3 years

    I am trying to delete a "Contact" from the "Contacts" table using the following @DELETE method (using Jersey Framework (JAX-RS implementation)

    @DELETE
    @Path("/delete/{contact}")
    public String deleteContact(@PathParam("contact") String name) throws ClassNotFoundException, SQLException {
    
        String response = DAOaccess.deleteContact(name);
        return response; 
    }
    

    And the following url is used to invoke the webservice from the browser:

    /contacts/delete/contactname

    But HTTP Status 405 - Method Not Allowed is thrown on doing so.

    What might be the reason? How do I overcome this?

  • DominikAngerer
    DominikAngerer almost 10 years
    I found this questions now in 2014 at one of top search results so I need to do a little update on this. There is a really good Client for the test of webservices. So feel free and have a look at: getpostman.com It's a really nice tool to simulate a web client. You can add collections with every call you do and with every type you want - GET, POST, PUT, DELETE, PATCH, ...