Fight to find anyone who is experiencing a similar problem or something similar.
I am currently consuming a stream via http (json) that has a GZip requirement, and I am experiencing a delay from sending data when reader.ReadLine() reads it. I was suggested that this could be related to decoding, storing data in a buffer?
This is what I have now, it works great except for the delay.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint); request.Method = "GET"; request.PreAuthenticate = true; request.Credentials = new NetworkCredential(username, password); request.AutomaticDecompression = DecompressionMethods.GZip; request.ContentType = "application/json"; request.Accept = "application/json"; request.Timeout = 30; request.BeginGetResponse(AsyncCallback, request);
Then inside the AsyncCallback method, I have:
HttpWebRequest request = result.AsyncState as HttpWebRequest; using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result)) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (string.IsNullOrWhiteSpace(line)) continue; Console.WriteLine(line); } }
It just sits on reader.ReadLine() until more data is received, and then even cancels some of it. There are also new symbols of new life, which are often read right away when he decides to read something.
I tested a stream running side by side with the curl command running, the curl command receiving and decompressing the data is perfectly fine.
Any insight would be awesome. Thanks,
Dan
EDIT No luck using buffer size on streamreader.
new StreamReader(stream, Encoding.UTF8, true, 1)
EDIT Also no luck updating .NET 4.5 and using
request.AllowReadStreamBuffering = false;