为什么Restlet中的Status.CLIENT_ERROR_UNAUTHORIZED在发布时返回EmptyRepresentation

时间:2015-03-06 13:15:31

标签: restlet restlet-2.0

Restlet 2.x中的Post方法在Status.CLIENT_ERROR_UNAUTHORIZED时返回EmptyRepresentation,在Get-method中不会这样做。

为什么?

1 个答案:

答案 0 :(得分:1)

我无法重现你的问题。你能给出你使用的代码吗?我可以尝试一下吗?我猜您使用方法setStatus,但是您应该使用此状态代码抛出ResourceException

使用此代码时:

public class TestServerResource extends ServerResource {
    @Post
    public Representation test(Representation repr) {
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
    }
}

我有以下回应:

405 Method Not Allowed
<html>
<head>
  <title>Status page</title>
</head>
<body style="font-family: sans-serif;">
  <p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Method Not Allowed</p>
  <p>The method specified in the request is not allowed for the resource identified by the request URI</p>
  <p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6">here</a>.<br>
  Please continue your visit at our <a href="/">home page</a>.
  </p>
</body>
</html>

希望它会对你有所帮助。 亨利