简体   繁体   中英

HttpClient buffers response stream on Windows Phone

I'm using the latest HttpClient (portable) library, to download files, the code is the following:

            var httpClient = new HttpClient();
            var request = new HttpRequestMessage(method, _path);

            var operation = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
            var stream = await operation.Content.ReadAsStreamAsync();

            do
            {
                var read = await stream.ReadAsync(buffer, 0, 4096);
                ReportProgress(...);
                (...)
            } while (...);

On Windows Phone the ReadAsync is downloading all the content before returning, so even if I configured it only to read the next 4096 bytes it reads all of them and only then returns. The issue here is that I want to report download progress, with this behaviour it basically makes it impossible, because it only reports anything after everything is downloaded.

The strangest thing is that the exact same code on the Windows 8.1 works great with no issues at all, it seams to be a Windows Phone only issue.

Any ideas?

I've observed similar thing a while ago , this is also related .

This is related to OS and probably you won't be able to bypass this easily (I've been there). If you strongly need this, you may try to follow @yasen's answer .

The good news is that it has been corrected in Windows 10 and your code should work there fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM