球衣client.setChunkedEncodingSize(null)无法正常工作 [英] Jersey client.setChunkedEncodingSize(null) not working

查看:138
本文介绍了球衣client.setChunkedEncodingSize(null)无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个客户端来评估基于REST的Jersey服务的Web服务性能.我已经编写了一些代码来测量响应时间并测量从服务器发送的字节数,但是response.getLength()方法始终返回-1.

I am writing one client to measure Jersey, REST based web service performance. I have written some code to measure response time and to measure number of bytes sent from the server but response.getLength() method always returning -1.

在许多质量检查论坛中,我读到设置client.setChunkedEncodingSize(null)可以工作,但是即使设置了该设置,我也会得到-1.

In many QA forum I read that setting client.setChunkedEncodingSize(null) will work but even after setting this, I am getting -1.

从服务器端,我将根据客户端发送的参数发送XML或JSON或protobuf类型的响应.对于所有这些响应类型,我得到的响应长度为-1.

From server side, I am sending response of type XML or JSON or protobuf depending upon parameters sent by client. For all of these response types, I am getting response length as -1.

我的实际要求如下:

WebResource webResourceQuery = client.resource(requestUrl);
ClientResponse response = webResourceQuery.header("Authorization", header)
                                          .accept(MediaType.APPLICATION_JSON)
                                          .get(ClientResponse.class);

从服务器端看,我没有明确设置content-length.有人可以帮我在客户端获得内容长度吗?

From server side, I am not setting content-length explicitly. Can anyone please help me in getting content-length on client side?

该实验的整个目的是衡量哪种响应类型在响应时间和发送/接收的数据量方面更有效.

Whole purpose of this experiment is to measure which response type is more efficient in terms of response time and amount of data sent/received.

推荐答案

我遇到了同样的问题:client.setChunkedEncodingSize(null);无法正常工作.

I ran in to the same problem: client.setChunkedEncodingSize(null); does not work.

这实际上使我禁用了分块编码:

This worked for me to actually disable chunked encoding:

client.getProperties().put(ApacheHttpClient4Config.PROPERTY_ENABLE_BUFFERING, true);

这篇关于球衣client.setChunkedEncodingSize(null)无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆