使用 HTTP OPTIONS 检索有关 REST 资源的信息

发布于 2024-07-18 09:50:10 字数 395 浏览 4 评论 0原文

这个问题与 Restlet 框架和 Java 有关。

当客户端想要发现服务器上可用的资源时,它们必须发送一个以 OPTIONS 作为请求类型的 HTTP 请求。 我想这对于非人类可读的客户端来说很好 - 即在代码而不是浏览器中。

我在这里看到的问题是 - 使用 GET 的浏览器(人类可读)将无法快速发现可用的资源并找到一些额外的帮助文档等 - 因为它们不使用 OPTIONS 作为请求类型。

有没有办法让浏览器发送 OPTIONS/GET 请求,以便服务器可以将格式化的 XML 发回客户端(因为这是 Restlet 中发生的情况 - 即服务器响应将以 XML 形式发回所有信息),并显示这是在浏览器中吗? 或者我的想法全错了 - 即 OPTIONS 的要点是它应该在客户端代码中使用,而不是通过浏览器读取。

This problem relates to the Restlet framework and Java

When a client wants to discover the resources available on a server - they must send an HTTP request with OPTIONS as the request type. This is fine I guess for non human readable clients - i.e. in code rather than a browser.

The problem I see here is - browsers (human readable) using GET, will NOT be able to quickly discover the resources available to them and find out some extra help documentation etc - because they do not use OPTIONS as a request type.

Is there a way to make a browser send an OPTIONS/GET request so the server can fire back formatted XML to the client (as this is what happens in Restlet - i.e. the server response is to send all information back as XML), and display this in the browser?
Or have I got my thinking all wrong - i.e. the point of OPTIONS is that is meant to be used inside a client's code and not meant to be read via a browser.

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

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

发布评论

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

评论(2

蓝梦月影 2024-07-25 09:50:10

Use the TunnelService (which by default is already enabled) and simply add the method=OPTIONS query parameter to your URL.

(The Restlet FAQ Q19 is a similar question.)

哀由 2024-07-25 09:50:10

我认为 OPTIONS 并不是设计为“用户可见”的。

您将如何从浏览器发送 OPTIONS 请求? (请注意,表单元素仅允许获取和发布)。

您可以使用 XmlHttpRequest 发送它,然后在 Javascript 回调中返回 XML 并适当地呈现它。 但我不相信这是您的用户应该真正了解的事情!

I think OPTIONS is not designed to be 'user-visible'.

How would you dispatch an OPTIONS request from the browser ? (note that the form element only allows GET and POST).

You could send it using XmlHttpRequest and then get back XML in your Javascript callback and render it appropriately. But I'm not convinced this is something that your user should really know about!

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