在Java中,我怎么能只在HttpPost中提供协议缓冲区的内容?

时间:2013-01-03 19:30:43

标签: java protocol-buffers apache-httpclient-4.x

我已尝试使用ByteArrayEntity,如下所示,但这会发送不在协议缓冲区本身的额外字节。是否只有POST内容的实体?

        byte [] info;

        ... [info initialized] ...

        HttpPost httppost = new HttpPost("https://myurl");
        ByteArrayEntity reqEntity = new ByteArrayEntity(info);

        reqEntity.setContentType("binary/octet-stream");
        reqEntity.setChunked(true);
        httppost.setEntity(reqEntity);

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

1 个答案:

答案 0 :(得分:0)

答案是令人失望的平庸:通过调用setChunked(true)添加了额外的字节。删除呼叫只会导致“info”中的字节被发送。