How to properly send an HTTP message to the client

后端 未结 7 1268
一生所求
一生所求 2021-02-05 00:14

I\'m working on a RESTful web service in Java. I need a good way to send error messages to the client if something\'s wrong.

According to the Javadoc, HttpServlet

7条回答
  •  自闭症患者
    2021-02-05 00:32

    I don't think any RESTful client would expect to look at the reason phrase to figure out what went wrong; most RESTful services I've seen/used will send the standard status info and an expanded message in the body of the response. sendError(int, String) is ideal for that situation.

提交回复
热议问题