Jersey Http客户端在POST请求上回复411 [英] Jersey Http Client replying with 411 on POST request

查看:145
本文介绍了Jersey Http客户端在POST请求上回复411的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jersey HTTP Client发送POST请求并接收到411 Content Length缺少响应. 但是,并非在所有情况下都会引发此错误.我在使用json内容类型的地方有一些电话,它工作正常.

I'm using Jersey HTTP Client for sending POST request and receiving 411 Content Length missing in response. However this error is not thrown in all the cases. There are some calls where I'm using json content type and it is working fine.

对于这个将请求发送到特定URL的特定请求,我收到411内容长度要求.当我使用不同的URL时具有相同的有效负载时,效果很好.

For this particular request where I'm sending the request to a specific URL I'm receiving 411 Content Length required. While with the same payload when I'm using a different URL it is working fine.

这是我在Jersey客户请求中设置表单实体的方式

This is how I'm setting Form Entity in Jersey Client Request

public static MultivaluedMap<String, String> getMultivaluedMapRequest(Map<String, String> map) {
    MultivaluedMap<String, String> bodyParams = new MultivaluedHashMap<String, String>();

    if (null != map && map.size() > 0) {
        for (Entry<String, String> param : map.entrySet()) {
            bodyParams.add(param.getKey(), param.getValue());
        }
    }
    return bodyParams;
}

private static Entity<?> getRequestEntity(final HttpRequestPayload<?> payload) {
    if (payload.getEntity() instanceof MultivaluedMap<?, ?>) {
        return Entity.form((MultivaluedMap<String, String>) payload.getEntity());
    } else {
        return Entity.entity(payload.getEntity(), payload.getMediaTypeProduced());
    }
}

这是拨打电话的方式

final Entity<?> entity = getRequestEntity(payload);

Response response = target.request(payload.getMediaTypeConsumed()).headers(payload.getHeaders()).post(entity);

我不确定是什么问题.我认为这与我向其发送请求的URL有关.

I'm not sure what the issue is. I think it has something to do with the URL I'm sending the request to.

推荐答案

HttpClientConnectionManager的ClientProperties.REQUEST_ENTITY_PROCESSING默认设置为CHUNKED. 作为解决方案,我将其设置为BUFFERED并可以正常工作.

HttpClientConnectionManager has the ClientProperties.REQUEST_ENTITY_PROCESSING set to CHUNKED by default. As a solution I set it to BUFFERED and it worked.

ClientConfig配置= new ClientConfig(); configuration.property(ClientProperties.REQUEST_ENTITY_PROCESSING,RequestEntityProcessing.BUFFERED);

ClientConfig configuration = new ClientConfig(); configuration.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);

这篇关于Jersey Http客户端在POST请求上回复411的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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