我建议更改JAX-
RS注释方法的签名以返回
javax.ws.rs.core.Response对象。根据您打算重定向是永久重定向还是临时重定向(即客户端是否应更新其内部引用以反映新地址),该方法应构建并返回
Response对应于HTTP-301(永久重定向)或HTTP的内容。
-302(临时重定向)状态码。
这是Jersey文档中有关如何返回自定义HTTP响应的描述:https
:
//jersey.java.net/documentation/latest/representations.html#d0e5151。我尚未测试以下代码段,但我想对于HTTP-301,代码看起来像这样:
@POSTpublic Response yourAPIMethod() { URI targetURIForRedirection = ...; return Response.seeOther(targetURIForRedirection).build();}…或针对HTTP-302:
@POSTpublic Response yourAPIMethod() { URI targetURIForRedirection = ...; return Response.temporaryRedirect(targetURIForRedirection).build();}


