如何解决为什么不能在反应堆网络中订阅请求?
我只想访问react-netty项目中的Http内容。但是结果为空。
代码在下面。
DisposableServer server =
HttpServer.create()
.host("localhost")
.port(8000)
.route(routes ->
.post("/echo",(request,response) ->
{ request.receive()
.retain()
.aggregate()
.asString()
.subscribe(System.out::println);
return response.sendString(Mono.just("hello"));})
.bindNow();
我无法在控制台中获得结果。
我可以像在代码中一样访问请求吗? 有人可以帮忙吗?谢谢。
解决方法
您在接收到请求数据之前返回响应,因此Reactor Netty将删除在发送响应后接收到的所有传入数据。
我不知道您的用例,但是将示例更改为下面的示例,您将能够看到传入的数据:
DisposableServer server =
HttpServer.create()
.host("localhost")
.port(8000)
.route(routes ->
routes.post("/echo",(request,response) ->
response.sendString(request.receive()
.retain()
.aggregate()
.asString()
.flatMap(s -> {
System.out.println(s);
return Mono.just("hello");
})))
)
.bindNow();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。