如何使用 Restlet 2.0 从 REST 服务器资源访问 GET 请求的正文?

发布于 2024-11-06 18:35:08 字数 432 浏览 0 评论 0原文

我想从 REST 服务器资源(使用 Restlet 2.0)访问 GET 请求的正文。这有几个原因:

  • 我想在 GET 请求中发送参数(以 JSON 格式),例如“返回具有这些字段/值的完整对象...”

  • 我想使用以下方法来保护 URL 请求的参数https,如果我将它们指定为 url 参数,我将无法保护

  • 我想避免很长的网址。

我还在阅读: HTTP GET with request body

我正在查看代码/示例和 api,但我没有找到解决方案,你能建议我一种方法吗?您看到更好的框架/解决方案吗? 谢谢 !!! 科西斯基

i would like to access the body of a GET request from a REST server resource (with restlet 2.0). This for a few reasons:

  • i would like to send parameters (in a JSON format) in the GET request, lets say for example "return the full object that has these fields/values ... "

  • i would like to protect the parameters of the URL request using https, and if i specify them as url parameters i cant protect them.

  • i would like to avoid very long urls.

i was also reading: HTTP GET with request body

i was looking in the code/examples and the api but i didn't find a solution, could you suggest me an approach? do you see a better framework/solution?
thanks !!!
kocisky

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

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

发布评论

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

评论(2

要走就滚别墨迹 2024-11-13 18:35:08

为什么不使用 POST?您已经放弃了通过在正文中包含条件来缓存响应的能力。那么使用 GET 有什么好处呢?

与发送 GET 主体相比,使用 POST 对 HTTP 规范的破坏程度要小一些。

Why not use POST? You already threw away the ability to cache responses by including the criteria in the body. So what benefit is there to using GET?

Using POST has to be less of a subversion of the HTTP spec than sending a GET body.

墨洒年华 2024-11-13 18:35:08

为了做你想做的事,你需要使用Restlet的Request和Client API。使用 ClientResource 类无法完成此操作。您可以在下面找到一些实现该功能的提示:

String endpoint = "http://localhost:8084/accounts/accountId/mails/mailId";
Request request = new Request(Method.GET, endpoint);
StringRepresentation representation = new StringRepresentation(
                                  "param1=value1¶m2=value2");
request.setEntity(representation);

Context context = new Context();
context.getParameters().add("tracing", "true");
Client client = new Client(context, Protocol.HTTP);
Response response = client.handle(request);

跟踪参数允许您查看使用内部 Restlet 连接器时实际发送的内容。

希望对你有帮助,
蒂埃里

In order to do what you want, you need to use the Request and Client API of Restlet. This can't be done using the ClientResource class. You can find below some hints to implement that:

String endpoint = "http://localhost:8084/accounts/accountId/mails/mailId";
Request request = new Request(Method.GET, endpoint);
StringRepresentation representation = new StringRepresentation(
                                  "param1=value1¶m2=value2");
request.setEntity(representation);

Context context = new Context();
context.getParameters().add("tracing", "true");
Client client = new Client(context, Protocol.HTTP);
Response response = client.handle(request);

The tracing parameter allows you seeing what is actually sent when using the internal Restlet connector.

Hope it'll help you,
Thierry

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