Bug 23966 - HttpClient.GetStreamAsync behaves differently from .Net
Summary: HttpClient.GetStreamAsync behaves differently from .Net
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.8.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2014-10-21 14:31 UTC by Alexandre Pepin
Modified: 2015-01-13 07:25 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:


Description Alexandre Pepin 2014-10-21 14:31:48 UTC
I want to be able to read a http stream before that all the response is received.
This code works perfectly with the .Net framework :

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
var stream = client.GetStreamAsync("http://www.google.com").Result;

using (var reader = new StreamReader(stream))
    while (!reader.EndOfStream)
        string lineRead = reader.ReadLine();

The code blocks at "!reader.EndOfStream" and as soon as there is new data in the stream, I can read it.

In mono, the code blocks at "var stream = client.GetStreamAsync("http://www.google.com").Result;" and only unblocks when all the data is received. I think it is because in mono, in the GetStreamAsync method, you set the HttpCompletionOption to ResponseContentRead while it should be set to ResponseHeadersRead

Workaround :
Instead of using GetStreamAsync to get the stream, I can use "GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result.Content.ReadAsStreamAsync().Result"
Comment 1 Marek Safar 2015-01-13 07:25:16 UTC
Fixed in master

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Create a new report for Bug 23966 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: