提问人:WWW 提问时间:11/14/2023 最后编辑:Stephen CWWW 更新时间:11/14/2023 访问量:40
如何使用Apache HttpClient测量每个请求传输的字节数?
How to measure bytes transmitted out for per request by using Apache HttpClient?
问:
我使用Apache HttpClient(5.2.1)来调用请求,使用PoolingHttpClientConnectionManager来管理连接,并使用Gzip压缩HTTP内容。
HttpEntity entity = new GzipCompressingEntity(stringEntity);
现在,我想测量每个请求传出的字节数。
我正在尝试使用 responseInterceptor 来获取传输的字节数,但它实际上测量的是每次连接发送的字节数,而不是每个请求发送的字节数。
HttpClientBuilder.create()
.addResponseInterceptorFirst(
(httpResponse, entityDetails, httpContext) -> {
try {
long bytesSent = ((HttpClientContext) httpContext)
.getEndpointDetails().getSentBytesCount();
} catch (Exception ex) {
// ...
}
})
.setConnectionManager(poolingHttpClientConnectionManager)
.build();
有没有办法测量每个请求发送的字节数?
答: 暂无答案
评论