Java – Jersey ‘nocontent’ response returns 200 instead of 204

I'm using Jersey (1.18) to build a rest API for my web application In part of my code, I have the following code snippet

return Response.status(Status.NO_CONTENT).entity(err_message).build();

Where status is com sun. jersey. api. client. ClientResponse. Instance of status;

According to Jersey documentation, No_ Content should return 204 code instead of this. The HTTP response has a header containing 200 codes

I tried to change the above code to

return Response.noContent().entity(err_message).build();

But the problem remains As a side note, use not_ Found instead of no_ Content, returns the 404 header as expected

About 'how to return 204 code?' Any suggestion that it was a mistake or what I did wrong

Note: not a copy of returning 200 response code instead of 204

Solution

See this so answer,

In other words, if you want "no_content", don't include content in the reply

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>