Bug 27265 - HttpClient fails on result 302 redux
Summary: HttpClient fails on result 302 redux
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: 3.12.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-02-20 14:24 UTC by PJ
Modified: 2015-03-05 01:32 UTC (History)
3 users (show)

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

Test case (193.09 KB, application/zip)
2015-02-20 14:24 UTC, PJ

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 GitHub or Developer Community 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:

Description PJ 2015-02-20 14:24:58 UTC
Created attachment 9952 [details]
Test case

This bug was originally reported in bug 14783, comment 9. Since the original test case in the bug passes, I'm filing a new bug to track this variant of the issue.

The test fails when using the URL provided by the customer in 14783, comment 9:

	public void Bug14783Test2 ()

		var c = new HttpClient ();

		catch (Exception e) {
			Assert.Fail (e.Message);


Exception: https://gist.github.com/pjbeaman/a2c7673b9cbbbb3a0c61

This test can be run in a regular console project, I've attached a complete solution. 


Xamarin Studio
Version 5.7.1 (build 17)
Installation UUID: a543a0ec-ca29-4f46-9d7a-9fb8715251af
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

Operating System
Mac OS X 10.9.5
Darwin PJS-IMAC.local 13.4.0 Darwin Kernel Version 13.4.0
    Wed Dec 17 19:05:52 PST 2014
    root:xnu-2422.115.10~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2015-02-23 05:15:01 UTC
.NET throws same exception in this case
Comment 3 Marek Safar 2015-02-23 17:19:12 UTC
Yes, I cannot think of any easy workaround. Quick search on SO reveals this http://stackoverflow.com/questions/22336301/handling-http-302-with-httpclient-on-wp8
Comment 4 Russell Fustino 2015-02-25 21:51:52 UTC
actually, here is an new piece of info on this. the wp8 client works fine as is. It is only a problem in the Android and iOS Xamarin Forms apps. Do you think it is platform browser related on the device on how it handles the requests? Do those browsers implement autoredirects? Is there a setting for this?  Any other ideas here before I implement this 302 error handling in the URL above in comment 3? It takes a while for the 302 to come back and the user needs to wait a long time before this error is trapped, so it is not an ideal solution.
Comment 5 Marek Safar 2015-02-27 06:11:28 UTC
What version are you using with wp8 client? I've tested this only against official .net 4.5 System.Net.Http assembly.
Comment 6 Russell Fustino 2015-02-28 22:43:20 UTC
I am using NuGet package. 

Microsoft HTTP Client Libraries

\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile78\
NuGet package Microsoft.Net.Http  2.2.29 published 2/25/15


C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Xamarin.iOS\v1.0\
Runtime version: v2.0.50727

Runtime version v4.0.30319

Runtime version v2.0.50727
Version =

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Net.Http.dll

Runtime Version: v4.0.30319


.NET C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile78\

Does it look OK to you? Does this help? Any more clues? 

I uninstalled and reinstalled Microsoft HTTP Client Libraries to no avail. 

For a moment there I thought I installed the NuGet package for System.net.http as that is out of date, but that was not it, I used Microsoft HTTP Client Libraries all the way. For a work around, I did a spreadsheet with an add-in to export XML. So I can use that for now. It was only about 30 shows on the tour so I just banged that out. That will be my backup plan. I could always automate that process in the future as well. Did you hear Ian Anderson just announced he is doing a fall tour with  the "Jethro Tull Rock Opera"! He is a mad man! Very hard worker for sure!
Comment 7 Marek Safar 2015-03-02 09:00:20 UTC
I am not sure what's wrong here.

Testing any other 302 redirect sites work for me. This fail for me with any Http client version and now timeouts for me, it looks like some bad response from the site is involved causing different result on different platforms.
Comment 8 Russell Fustino 2015-03-02 13:03:54 UTC
You probably tripped to firewall from testing so much, the same thing happened to me. I can pass your ip address along to the web master to free it up for you, if you like. I can also do some fishing around with him and pass along your comment if you like. Am I testing with the right versions of system.net.http? Also, if you type that feed into a browser on the native platforms, it works.
Comment 9 Marek Safar 2015-03-03 09:27:54 UTC
OK, I've done some more testing and it's clearly server issue. It requires User-Agent header to be set.

Changing your code to

var c = new HttpClient ();
c.DefaultRequestHeaders.Add ("User-Agent", "AppleWebKit/537.36 (KHTML, like Gecko)");
var res = c.GetStringAsync ("http://jethrotull.com/?feed=gigpress&artist=2").Result;

will give you correct response on all platforms.
Comment 10 Russell Fustino 2015-03-04 03:40:28 UTC
Android works! I will try IOS tomorrow. Now all I need is to figure our how to parse the description field into a nicely formatted page. Any resources on how to do that using xaml in xamarin forms that you can point me to would be appreciated. Thanks so much for staying with this. Much appreciated Marek!
Comment 11 Russell Fustino 2015-03-05 01:32:56 UTC
iOS works too! Great job! Thanks so much!