我有以下方法:
private static final String UTF_8 = "UTF-8";
private static final int TIMEOUT = 5000;
private static final String DATASTREAM_URI = "MY_VALID_URL_HERE";
@Override
public Response logHttpMessage(final String logHttpMessageXml) throws UnsupportedEncodingException {
final Client client = new ResteasyClientBuilder()
.establishConnectionTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
.socketTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
.build();
final WebTarget target = client.target(DATASTREAM_URI);
return target.request().header(HttpHeaders.CONTENT_LENGTH, logHttpMessageXml.getBytes(UTF_8).length)
.post(Entity.entity(logHttpMessageXml, MediaType.APPLICATION_XML_TYPE));
}
我通过执行以下操作添加标头: .header(HttpHeaders.CONTENT_LENGTH,logHttpMessageXml.getBytes(UTF_8).length)
但在执行请求时我收到此错误:
注意:我需要设置内容长度以禁止分块,我的休息端点(在我的控制之外)不会对分块数据做出正确的反应。
我一直在网上搜索但没有找到解决方案,我该如何解决?提前谢谢!