java Jersey Response.ok() 没有给出 200 OK

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9939040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:58:51  来源:igfitidea点击:

Jersey Response.ok() not giving 200 OK

javahttpjersey

提问by TechSpellBound

This is the piece of code that I am using.

这是我正在使用的一段代码。

The ok(Object items) method is internally calling Jersey's Response.ok() method when items is null.

当 items 为空时,ok(Object items) 方法在内部调用 Jersey 的 Response.ok() 方法。

    MembershipRequestModel membershipRequest = null;
    membershipRequest = communityService.addUserToCommunity(communityId, userId);
    if(membershipRequest != null) {
    // Add code 303 if returning membershiprequest
    return seeOther( membershipRequest, 
                   String.valueOf(membershipRequest.getId()), 
                   MembershipRequestRestHandlerImpl.class);
    } else {
    return ok(null);
}

public Response ok() {
    return Response.ok().build();
}

public Response ok(Object items) {
  if ( items == null )
    return ok();

  return Response.ok().entity(items).build();
}

But, I am getting the response as 204 No Content which should have actually been 200 OK. I have tried it using RESTClient firefox plugin and cURL command on CentOS.

但是,我得到的响应是 204 No Content,实际上应该是 200 OK。我已经在 CentOS 上使用 RESTClient firefox 插件和 cURL 命令尝试过它。

Please help.

请帮忙。

Thanks.

谢谢。

回答by fmucar

If there is no body, 204will be returned.

如果没有尸体,204将被退回。

all 2XXare success.

一切2XX都是成功的。

204means success with no content (no entity body).

204意味着没有内容(没有实体主体)的成功。

www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

www.w3.org/Protocols/rfc2616/rfc2616-sec10.html