Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am unable to read the chunk size of the first chunk from a webresponse stream.
What am I missing ?

Here is my code, in hexChunkSizeCount I am expecting in hex format the chunk size.
Instead I am getting the contents of the first chunk.
C#
WebResponse response = webRequest.GetResponse();
if(response.Headers["transfer-encoding"].ToLower().Equals("chunked"))
{
Stream chunkedStream = response.GetResponseStream();
StreamReader sr = new StreamReader(chunkedStream);
string hexChunkSizeCount = sr.ReadLine(); // expecting chunk size, but getting chunk content
}
Posted
Updated 3-Jan-13 17:06pm
v2

1 solution

sr.ReadLine(); will give back content, as designed.
Details here: MSDN: StreamReader.Read Method [^]

If you need any info around size, the internal buffer size of a StreamReader is 2k. Refer: StreamReader and buffer in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900