Bug 31004 - System.Net.Http.HttpClient doesn't work on iOS 9
Summary: System.Net.Http.HttpClient doesn't work on iOS 9
Status: VERIFIED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 8.10
Hardware: PC Mac OS
: --- normal
Target Milestone: 9.0 (iOS9)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-10 18:05 UTC by Frank A. Krueger
Modified: 2015-06-26 10:38 UTC (History)
7 users (show)

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


Attachments
Sample async sample (5.15 KB, application/x-gzip)
2015-06-10 21:36 UTC, Miguel de Icaza [MSFT]
Details


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.

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.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED INVALID

Description Frank A. Krueger 2015-06-10 18:05:32 UTC
For example,

await client.GetStringAsync ("http://xamarin.com")

never returns. No exceptions are thrown and nothing is logged to the console.

Replacing the code with System.Net.WebRequest fixes everything.

Full code:

		static HttpClient CreateClient ()
		{
			var h = new HttpClientHandler {
				AllowAutoRedirect = true,
				AutomaticDecompression = DecompressionMethods.Deflate|DecompressionMethods.GZip,
				MaxAutomaticRedirections = 20,

			};
			var cli = new HttpClient (h);
			cli.Timeout = TimeSpan.FromSeconds (20);
			var req = cli.DefaultRequestHeaders;

			req.UserAgent.Clear ();
			req.UserAgent.Add (new ProductInfoHeaderValue ("Mocast", "1.0"));
			req.Accept.Clear ();
			req.Accept.Add (new MediaTypeWithQualityHeaderValue ("application/xml"));
			req.Accept.Add (new MediaTypeWithQualityHeaderValue ("*/*", 0.8));

			return cli;
		}

		static readonly Lazy<HttpClient> sharedClient = new Lazy<HttpClient> (CreateClient);

		static HttpClient GetClient ()
		{
			return sharedClient.Value;
		}

		public static async Task<string> GetAsync (string url)
		{
			Console.WriteLine ("GetAsync " + url);
			var r = await Task.Run (() => Get (url));
			Console.WriteLine ("GotAsync " + url);
			if (!string.IsNullOrEmpty (r) && r [0] == 0xFEFF) {
				r = r.Substring (1);
			}
			return r;
		}
Comment 1 Miguel de Icaza [MSFT] 2015-06-10 21:35:33 UTC
I am using a recent build (that includes the page and libc fixes) on a 64 bit iOS 9 device.

I could not use your sample as-is since a couple of bits are missing, but took the CreateClient and used that to call the method you mentioned at the beginning, and it works.

Attached is my version.
Comment 2 Miguel de Icaza [MSFT] 2015-06-10 21:36:01 UTC
Created attachment 11562 [details]
Sample async sample
Comment 3 Frank A. Krueger 2015-06-11 12:34:10 UTC
This looks like a false alarm.

I tested with 8.10.2.22.

I ran your sample Miguel and that worked.

I then moved Mocast back to HttpClient and it works now.

Not sure what its problem was yesterday, but all's well now.
Comment 4 Saurabh 2015-06-25 03:06:40 UTC
I am also getting exception using attached project when I run it.
Exception details: https://gist.github.com/Mohit-Kheterpal/2eb6d4b7e59aad0f8651 


As per Comment#3 Changing the status to Verified.