return Response.status(Status.NO_CONTENT).entity(err_message).build();
其中Status是com.sun.jersey.api.client.ClientResponse.Status的实例;
根据Jersey文档,NO_CONTENT应返回204代码,而不是这个,http响应有一个包含200个代码的标头.
NO_CONTENT@H_301_10@ public static final ClientResponse.Status NO_CONTENT@H_301_10@ 204 No Content,see HTTP/1.1 documentation.
我试图将上述代码更改为
return Response.noContent().entity(err_message).build();
但问题仍然存在.@H_301_10@作为旁注,使用NOT_FOUND而不是NO_CONTENT,按预期返回404标头.
解决方法
…204 means “No Content”,meaning that the response contains no@H_301_10@ entity,but you put one in it. It’s likely that Jersey is switching it@H_301_10@ to a 200 for you,which is basically identical to a 204 except that it@H_301_10@ contains a response entity.
Finally,you can get 204 responses very simply by a couple of built-in@H_301_10@ behaviors: void methods and null return values both map to a 204@H_301_10@ response. Otherwise,simply return
Response.status(204).build()
.