You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Gaurav Kumar <ga...@gmail.com> on 2013/05/31 06:58:21 UTC

Setting HTTP headers in InputStreamEntity

I
​ am using InputStreamEntity ​;  I am reading data from a file input stream
and sending it to remote server ; everything seems to be working fine.

​Now, I would like to be able to set a header just before inputstream
finishes i.e. as soon as I read the last but one byte, I want to set a
header.
See below sample code-

Re: Setting HTTP headers in InputStreamEntity

Posted by Gaurav Kumar <ga...@gmail.com>.
Hit send too soon-

The code is-

   long ctr = 0; int ch;
        while ((ch = inputStream.read()) >= 0) {

            if (lastByte) { //lastByte is set if this will be the only byte
left in inputStream
                httpPut.addHeader("hello", "there");
            }
        }

But above code doesn't set header.

I verified using Wireshark that headers have not been already sent so I
believe there is still an opportunity to set them.

Please suggest a way to handle this requirement. Thanks!






On Thu, May 30, 2013 at 9:58 PM, Gaurav Kumar <ga...@gmail.com>wrote:

> I
> ​ am using InputStreamEntity ​;  I am reading data from a file input
> stream and sending it to remote server ; everything seems to be working
> fine.
>
> ​Now, I would like to be able to set a header just before inputstream
> finishes i.e. as soon as I read the last but one byte, I want to set a
> header.
> See below sample code-
>
>
>