HTTP 删除,响应状态:405(不允许的方法)
HTTP Delete, Response Status: 405 (Method Not Allowed)
向我的服务器发送 http delete 时会发生这种情况
Response Status: 405 (Method Not Allowed)
header 看起来像这样
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
我怀疑我必须启用对 http 删除方法的访问,但不知道如何。
这是我的删除方法
@DELETE
@Path("/{id}")
public boolean deleteItem(@PathParam("id") long itemId);
这是删除url
wrong: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1
right: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1
我正在使用 jax-rs
import javax.ws.rs.DELETE;
Whosebug 上的这个老 post 可以回答你的问题:
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.
注解 @Path("/{id})"
需要 id
紧接在 /
之后,因此它与您的测试不匹配 URL
http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1
相反,删除 id=
:
http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1
向我的服务器发送 http delete 时会发生这种情况
Response Status: 405 (Method Not Allowed)
header 看起来像这样
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
我怀疑我必须启用对 http 删除方法的访问,但不知道如何。
这是我的删除方法
@DELETE
@Path("/{id}")
public boolean deleteItem(@PathParam("id") long itemId);
这是删除url
wrong: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1
right: http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1
我正在使用 jax-rs
import javax.ws.rs.DELETE;
Whosebug 上的这个老 post 可以回答你的问题:
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.
注解 @Path("/{id})"
需要 id
紧接在 /
之后,因此它与您的测试不匹配 URL
http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/id=1
相反,删除 id=
:
http://192.168.2.101:8080/DataAccessRemoteWebapp/rest/dataitem/1