将请求主体附加到VERTX请求

发布于 2025-02-01 10:29:07 字数 509 浏览 1 评论 0原文

在下面的顶点URL实例的我的Java示例代码中,URL在调用时返回JSON请求。我试图将请求主体附加到URL,但我被卡住了。这是一个示例片段,

Route handler2 = router
                .post("/get-a-file")
                .consumes("*/json")
                .handler(routingContext -> {
                    HttpServerResponse response = routingContext.response();
                    response.setChunked(true);
                    response.write("bla bla bla...");
                    response.end();
                });

只是在Vert.x上掌握了我的手。协助

IN my java sample code of a vertex URL instance below, The URL returns a json request when called. I am trying to append a request body to the URL but I am stuck. Here is a sample snippet

Route handler2 = router
                .post("/get-a-file")
                .consumes("*/json")
                .handler(routingContext -> {
                    HttpServerResponse response = routingContext.response();
                    response.setChunked(true);
                    response.write("bla bla bla...");
                    response.end();
                });

Just getting my hands on vert.x. Do assist

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

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

发布评论

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

评论(1

素食主义者 2025-02-08 10:29:07

对于vert.x 您的路线需要bodyhandler ,请访问主体。您应该在自己的处理程序之前添加它,以便当您的业务逻辑运行时,请求主体已经存在。

您的代码看起来应该与此相似:

...
.consumes("*/json")
.handler(BodyHandler.create())
.handler(routingContext -> ...

现在您可以在routingContext上访问主体并将其映射到您的DTO。

For request bodies in Vert.x your route needs a BodyHandler. You should add it before your own handler so that the request body is already there when your business logic runs.

Your code should look similar to this:

...
.consumes("*/json")
.handler(BodyHandler.create())
.handler(routingContext -> ...

Now you can access the body on routingContext and map it to your DTO.

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