Restlet 如何处理 HTTP Accept 标头?

发布于 2024-07-23 02:47:07 字数 138 浏览 3 评论 0 原文

Restlet 框架应该处理自动内容协商; 但是,它似乎做得不正确。

当客户端发送带有带有值的 Accept 标头的 HTTP GET 请求时,Restlet 不会自动协商内容。

有谁知道如何处理 Accept 标头?

The Restlet framework is supposed to handle automatic content negotiation; however, it doesn't seem to do it properly.

When a client sends and HTTP GET request with the Accept header with a value, Restlet doesn't automatically negotiates the content.

Does anyone know how the Accept header is treated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2024-07-30 02:47:07

Restlet API 广泛支持“Accept”标头。 该信息通过 Request.getClientInfo().getAcceptedMediaTypes()List

> 方法进行解析和获取。

现在,为了自动为您协商内容,Restlet 引擎需要了解有关可用变体的信息。 这是 Restlet 1.1 中 org.restlet.resource.Resource 类的用途,以及正在开发的 Restlet 2.0 版本中新的 org.restlet.resource.ServerResource 类。

在 Restlet 1.1 中,您创建 Resource 的子类,声明如下变体:

   getVariants().add(new Variant(MediaType.TEXT_PLAIN));

   getVariants().add(new Variant(MediaType.APPLICATION_XML));

然后重写 represent(Variant) 方法,如下所示:

public Representation represent(Variant){

  if(MediaType.TEXT_PLAIN.equals(variant.getMediaType()){

     ...

  else if(...)

     ...
}

谨致问候,
杰罗姆

PS:请使用我们的邮件列表来解决未来的问题并查看档案:
http://www.restlet.org/community/lists

The Restlet API has extensive support for the "Accept" header. The information is parsed and available via the Request.getClientInfo().getAcceptedMediaTypes() : List<Preference<MediaType>> method.

Now, in order to automatically negotiate content for you, the Restlet engine needs to have information about the available variants. This is the purpose org.restlet.resource.Resource class in Restlet 1.1 and the new org.restlet.resource.ServerResource class in the Restlet 2.0 version being developed.

In Restlet 1.1, you create a subclass of Resource, declare variants like this:

   getVariants().add(new Variant(MediaType.TEXT_PLAIN));

   getVariants().add(new Variant(MediaType.APPLICATION_XML));

Then override the represent(Variant) method like this:

public Representation represent(Variant){

  if(MediaType.TEXT_PLAIN.equals(variant.getMediaType()){

     ...

  else if(...)

     ...
}

Best regards,
Jerome

PS: please use our mailing list for future questions and look in the archives:
http://www.restlet.org/community/lists

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文