简体   繁体   中英

HTTP Delete, Response Status: 405 (Method Not Allowed)

when sending http delete to my server this happens

Response Status: 405 (Method Not Allowed)

header look like this

Date: Sat, 31 Jan 2015 19:17:47 GMT
Server: WildFly/8
Connection: keep-alive
X-Powered-By: Undertow/1
Content-Length: 0
Allow: HEAD, POST, GET, OPTIONS, PUT

I suspect that I have to enable access to http delete method, but don't know how.

this is my delete method

@DELETE
@Path("/{id}")
public boolean deleteItem(@PathParam("id") long itemId);

this is the url for delete

wrong: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1

right: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1

I am using jax-rs

import javax.ws.rs.DELETE;

The annotation @Path("/{id})" requires the id directly after the / and so it won't match your test URL

http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1

Instead, remove the id= :

http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1

This old post on stackoverflow can respond to you question :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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