Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using httpwebresponse asynchronously - chunked response?

17 views
Skip to first unread message

bobh...@gmail.com

unread,
Jun 25, 2009, 5:13:41 PM6/25/09
to

I have written a class that will asynchronously read the response
stream from an httpwebrequest. It uses the Stream.BeginRead method
inside my EndGetResponse callback function, and my Stream.EndRead
callback function will use BeginRead again until the EndRead callback
results in zero bytes read. Works great, and it should, since I
borrowed the framework from an example found in MSDN somewhere.

However, when the response is being sent with Transfer-Encoding =
Chunked, this technique appears to break. When my stream appears to
be exhausted, I have nothing but headers, no "payload".

I have tried, when the first stream is exhausted, using another
"BeginGetResponse" if the headers indicate chunking. No dice. I've
also attempted to get another stream after closing the first. Not
happening.

I've searched everywhere for example code that does this and handles
chunking, and so far, no success.

Please let me know if you think there's a better place to ask this
question, also.

Bob

Peter Duniho

unread,
Jun 25, 2009, 5:26:34 PM6/25/09
to
On Thu, 25 Jun 2009 14:13:41 -0700, Bob.remove...@gmail.ANDthis.com
<bobh...@gmail.com> wrote:

>
> I have written a class that will asynchronously read the response
> stream from an httpwebrequest. It uses the Stream.BeginRead method
> inside my EndGetResponse callback function, and my Stream.EndRead
> callback function will use BeginRead again until the EndRead callback
> results in zero bytes read. Works great, and it should, since I
> borrowed the framework from an example found in MSDN somewhere.
>
> However, when the response is being sent with Transfer-Encoding =
> Chunked, this technique appears to break. When my stream appears to
> be exhausted, I have nothing but headers, no "payload".
>
> I have tried, when the first stream is exhausted, using another
> "BeginGetResponse" if the headers indicate chunking. No dice. I've
> also attempted to get another stream after closing the first. Not

> happening. [...]

You should probably post a concise-but-complete code example that reliably
demonstrates the problem.

I haven't found anything definitive, but a variety of sources, including
MSDN, imply to me that HttpWebRequest/Response automatically handles
chunked transfers on your behalf. It may simply be an error in your own
code, or a misunderstanding of how to use the class. Without a proper
code example, there's no way to comment on it.

Pete

bobh...@gmail.com

unread,
Jun 25, 2009, 9:12:55 PM6/25/09
to
On Jun 25, 5:26 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Thu, 25 Jun 2009 14:13:41 -0700, Bob.removethis.Ho...@gmail.ANDthis.com  

>
. [...]
>
> You should probably post a concise-but-complete code example that reliably  
> demonstrates the problem.
>
> I haven't found anything definitive, but a variety of sources, including  
> MSDN, imply to me that HttpWebRequest/Response automatically handles  
> chunked transfers on your behalf.  It may simply be an error in your own  
> code, or a misunderstanding of how to use the class.  Without a proper  
> code example, there's no way to comment on it.
>
> Pete

Hi, Pete - I appreciate the rapid response. I can't really post the
code without some clean-up and sanitizing, but if that's what it will
take, I'll do that. It's really fundamentally the same code that can
be found in multiple threads in this very newsgroup, easiily found by
searching for BeginGetResponse. I was really hoping to find someone
who had done this, ran into the same problem, and would share their
solution. One of the problems a good samaritan like yourself will run
into, even with my code in hand, is finding a source of chunked
responses against which you can test.

To be continued...

Bob

Peter Duniho

unread,
Jun 25, 2009, 9:14:56 PM6/25/09
to
On Thu, 25 Jun 2009 18:12:55 -0700, Bob.remove...@gmail.ANDthis.com
<bobh...@gmail.com> wrote:

> [...] One of the problems a good samaritan like yourself will run


> into, even with my code in hand, is finding a source of chunked
> responses against which you can test.

Indeed. It's one of the reasons it's so important for the questioner
(you) to provide a complete, self-contained code example. Another person
could invest (and potentially waste) a great deal of time trying to even
reproduce the exact problem you're seeing.

Pete

0 new messages