Вопрос

I am trying to send use Ext.Ajax.request method to delete some data on server. My request method looks as below :

Ext.Ajax.request({
      url: '/myserver/restful/service/delete',
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json'
      },
      params: {
        userId: 12345
      }
});

On my jersey server I have written which looks like as below :

@Path("/delete")
  @DELETE
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response deleteUser(final String userId) {
    System.out.println("user id = " + userId);
    return Response.ok().entity("success").build();
  }

This method prints out user id in following format :

user id = userId=12345

So my expected value for userId is 12345 but it is giving me userId=12345. As I am newbie to jersey thing, I am not able to decide what to do now.

Can anyone please tell what is going wrong?

Это было полезно?

Решение

Not sure about what's going wrong in Jersey, but... if you are trying to use DELETE with a request body you're on the wrong track anyway. Don't. The only relevant parameter for DELETE should be the request URI it's being applied to.

Другие советы

@Julian is correct you really shouldn't have params with an HTTP DELETE verb.

Try this:

@Path("/delete/{userId} 

Then inside of your method:

@PathParam("userId") String userId

And then when you call your service change your url to : delete/(userId) (without the parens) and remove the params.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top