Re: getting binary data from HTTP Request

From: Igor N. Kolomiyets (list_at_inksystems.net)
Date: 02/02/04


Date: Mon, 02 Feb 2004 13:07:19 +0000

Shlomi,

my question was actually what format is your another application sending
data to your servlet? Can you post a sample of the POST request?

Best regards,
Igor.

Shlomi wrote:
> "Igor N. Kolomiyets" <list@inksystems.net> wrote in message news:<bvjaih$rob$1@kermit.esat.net>...
>
>>Hi,
>>
>>how binary data is being passed to the servlet? What is tha value in len
>>variable (getContentLength())?
>
>
>
> The len of the variable is somewhere between 300 - 350 bytes.
> i am integrating two programs that work on the web, i have another
> application that pass the binary data to my servlet.
>
> Thank you so much for your help !
> Shlomi
>
>
>
>>Best regards,
>>Igor.
>>
>>Shlomi wrote:
>>
>>>Hi.
>>>
>>>i have a servlet that receives a binary data in one of its parameters.
>>>i cannot read this binary data to a byte array for some reason
>>>when i am trying to use servletInputStream.available() i am getting 0.
>>>any suggestions ?
>>>what am i donig wrong ?
>>>
>>>here is my code :
>>>(don't look for syntax mistakes, i pasted the relevant code only)
>>>
>>>public void doPost(HttpServletRequest request, HttpServletResponse response)
>>> throws ServletException, IOException
>>>{
>>> throws ServletException, IOException
>>> {
>>> try
>>> {
>>> // get POSTED data
>>> // use servlet input stream
>>> ServletInputStream ins = request.getInputStream();
>>> //count length of data
>>> int len = request.getContentLength();
>>> //allocate bytes buffer
>>> byte[] buf = new byte[len];
>>> int offset = 0;
>>> do
>>> {
>>> int inputLen = ins.read(buf, offset, len - offset);
>>> // MY PROBLEM ----- inputLen always equals -1
>>> if (DEBUG)
>>> System.out.println("POST Input Length = " + inputLen);
>>>
>>> if (inputLen <= 0)
>>> {
>>> String msg = "read finished early - read " +
>>> offset + " of " + len + " bytes(contentLength)" ;
>>> throw new IOException(msg);
>>> }
>>> offset += inputLen;
>>> }
>>> }



Relevant Pages