在 HttpClient postAbs 中 2 分钟后得到响应 Vert.x
Getting response after 2mins in HttpClient postAbs Vert.x
我正在如下监听 Eventbus 并使用 vert.x
调用 HttpClient.postAbs()
public void start(Future<Void> fut) {
EventBus eb1 = MainAdminVx.serviceBack.getEventBus();
eb1.consumer("local-message-receiver", message -> {
HttpClient client = vertx.createHttpClient();
client.postAbs("http://external-server-address/test@xyz.com/activityIn?activityId=5", r -> {
r.bodyHandler(b -> System.out.println(b.toString() + r.statusCode() )
).exceptionHandler(t -> System.err.println(t.getMessage()));
})
.putHeader("content-length", "1000")
.putHeader("userId", "test@xyz.com")
.putHeader("Content-Type", "application/json")
.putHeader("Accept", "application/json")
.write("some text")
.exceptionHandler(System.err::println)
.end();
});
}
有什么我遗漏的吗?或者还有另一种方法可以做到这一点...因为我在 postAbs 中 2 分钟后得到响应,并且相同的 POST 请求在 postman 中运行很快。
提前致谢!!!
我们只需要设置
setChunked(true)
它就像一个魅力!!!
As I have set content-length as '1000' , so server will wait until it receives 1000 bytes even though your not sending anything and respond back after. It means the exact byte length of the HTTP body. Generally it is used for HTTP 1.1 so that the receiving party knows when the current response/request has finished, so the connection can be reused for another request.
那么什么是分块传输:
Chunked transfer encoding is a data transfer mechanism in version 1.1 of the Hypertext Transfer Protocol (HTTP) in which data is sent in a series of "chunks". It uses the Transfer-Encoding HTTP header in place of the Content-Length header, which the earlier version of the protocol would otherwise require. Because the Content-Length header is not used, the sender does not need to know the length of the content before it starts transmitting a response to the receiver. Senders can begin transmitting dynamically-generated content before knowing the total size of that content.
或者,可以省略内容长度并使用分块编码,或者如果两者都缺失,则在响应结束时必须关闭连接。
希望本文能帮助您理解 Http 块的概念。
我正在如下监听 Eventbus 并使用 vert.x
调用 HttpClient.postAbs() public void start(Future<Void> fut) {
EventBus eb1 = MainAdminVx.serviceBack.getEventBus();
eb1.consumer("local-message-receiver", message -> {
HttpClient client = vertx.createHttpClient();
client.postAbs("http://external-server-address/test@xyz.com/activityIn?activityId=5", r -> {
r.bodyHandler(b -> System.out.println(b.toString() + r.statusCode() )
).exceptionHandler(t -> System.err.println(t.getMessage()));
})
.putHeader("content-length", "1000")
.putHeader("userId", "test@xyz.com")
.putHeader("Content-Type", "application/json")
.putHeader("Accept", "application/json")
.write("some text")
.exceptionHandler(System.err::println)
.end();
});
}
有什么我遗漏的吗?或者还有另一种方法可以做到这一点...因为我在 postAbs 中 2 分钟后得到响应,并且相同的 POST 请求在 postman 中运行很快。
提前致谢!!!
我们只需要设置
setChunked(true)
它就像一个魅力!!!
As I have set content-length as '1000' , so server will wait until it receives 1000 bytes even though your not sending anything and respond back after. It means the exact byte length of the HTTP body. Generally it is used for HTTP 1.1 so that the receiving party knows when the current response/request has finished, so the connection can be reused for another request.
那么什么是分块传输:
Chunked transfer encoding is a data transfer mechanism in version 1.1 of the Hypertext Transfer Protocol (HTTP) in which data is sent in a series of "chunks". It uses the Transfer-Encoding HTTP header in place of the Content-Length header, which the earlier version of the protocol would otherwise require. Because the Content-Length header is not used, the sender does not need to know the length of the content before it starts transmitting a response to the receiver. Senders can begin transmitting dynamically-generated content before knowing the total size of that content.
或者,可以省略内容长度并使用分块编码,或者如果两者都缺失,则在响应结束时必须关闭连接。
希望本文能帮助您理解 Http 块的概念。