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

允我心安 提交于 2019-12-11 00:52:23

问题


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?


回答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.




回答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.



来源:https://stackoverflow.com/questions/12673212/http-status-405-method-not-allowed-error-on-invoking-a-delete-method-using-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!