What's the proper way to set the Location header for an HTTP 201 response in a Java Servlet application

前端 未结 5 1485
醉梦人生
醉梦人生 2021-01-31 02:49

Consider the following code sending an HTTP 201 \"Created\" response to the client:

    String url = \"/app/things?id=42\"; // example
    response.setStatus(Htt         


        
5条回答
  •  隐瞒了意图╮
    2021-01-31 03:20

    Just send the absolute path. The restriction to an absolute URI is a known defect in RFC 2616 and will be fixed in HTTPbis (see http://trac.tools.ietf.org/wg/httpbis/trac/ticket/185).

    Please note that RFC 7231 now includes relative URIs in the spec. See other answers for how to handle relative URIs.

提交回复
热议问题