问题描述
我只想访问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();