RestFul webservices 对错误代码的响应 [英] RestFul webservices Response for Error code

查看:51
本文介绍了RestFul webservices 对错误代码的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究提供 JSON 响应的 Restful Web 服务,当没有输入 id=11 的数据时,我得到以下输出

I am working on Restful Web Services which give JSON response and i got following output when there is no data for entered id=11

GET 请求失败请求失败 --> 状态:(204) 响应:{

GET Request Failed Request Failed --> Status: (204) Response: {

}

现在我希望该响应字段包含错误代码 = 204 的正确消息,例如无效请求"或id 不存在"

Now I want That response field contain proper message for error code=204 like "invalid request" or "id doesn't exist"

推荐答案

如果你使用的是 Jersey 或类似的 JAX-RS 框架,你可以修改你的代码类似于:

If you are using Jersey or similar JAX-RS framework you can modify your code similar to :

return Response.status(204).type("text/plain")
                .entity("Invalid Request!").build();

这篇关于RestFul webservices 对错误代码的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆