Bug 14783 - HttpClient fails on result 302
Summary: HttpClient fails on result 302
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-09-16 15:49 UTC by Bryan Moulton
Modified: 2015-02-20 14:26 UTC (History)
7 users (show)

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


Attachments
ConnectionManager class (3.12 KB, application/octet-stream)
2013-09-16 15:49 UTC, Bryan Moulton
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 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:
Status:
VERIFIED FIXED

Description Bryan Moulton 2013-09-16 15:49:18 UTC
Created attachment 4903 [details]
ConnectionManager class

In reference to case #43574

When using await HttpClient.GetStreamAsync(url), the HttpClient stops working and throws an exception when the server returns a 302 result (redirect). The same code using the Microsoft .Net implementation does not throw the exception and continues to work.

{System.Net.Http.HttpRequestException: 302 (Found)   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode () [0x0000d] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpResponseMessage.cs:122    at System.Net.Http.HttpClient+<GetStreamAsync>c__async8.MoveNext () [0x0008a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:307  --- End of stack trace from previous location where exception was thrown ---   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62    at System.Runtime.CompilerServices.TaskAwaiter`1[System.IO.Stream].GetResult () [0x00033] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59    at Xamarin.App4Sales.Common.Components.ConnectionManager+<GetStream>c__async1.MoveNext () [0x000a0] in /Users/User/Desktop/Xamarin App4Sales/Xamarin.App4Sales.Common.Components/ConnectionManager.cs:47 }               System.Net.Http.HttpRequestException
Comment 1 Marek Safar 2013-09-20 14:28:55 UTC
This works for me.

using System.Net.Http;

class X
{
	public static void Main ()
	{
		var c = new HttpClient ();
		c.GetStringAsync ("http://httpstat.us/302").Wait ();
	}
}


Do you have better repro?
Comment 3 Marek Safar 2013-09-24 10:01:29 UTC
Fixed in master
Comment 5 Marek Safar 2013-10-01 12:15:45 UTC
This is included in monotouch-7.0.2. Commit with bug number message is part of Mono commit log.
Comment 6 PJ 2013-10-01 13:21:36 UTC
The commit is only in mono/master and both monotouch 7.0.1 and monotouch 7.0.2 are tracking the monotouch-7.0.1-branch of mono.

Marek is saying to me here that the fix is low risk enough we could potentially get it onto 7.0.2, pending a discussion with sebastien.
Comment 9 Russell Fustino 2015-02-19 22:09:03 UTC
Same thing is happening to me in the current release of Xamarin Forms and it used to work in a prior version (unless something changed on the web site I am trying to hit, will know that soon). I am getting a 302 on a redirect using this rss feed:

http://jethrotull.com/?feed=gigpress&artist=2

The request gets routed thru CloudFlare. I have been working with the Jethro Tull Webmaster and he has made some fixes for me with getting a 522 Timeout Request due to all the testing ( :) ) ... and now we are down to a 302. This is a show stopper right now, as these are the tour dates feed. The Jethro Tull App is almost ready to publish! So any work around would be greatly appreciated! Miss you all!

Here is my code and configuration:

        private int retries=0;  
        public async Task<List<TourDate>> GetRecentBlogs()
        {
       
            using (var httpClient = new HttpClient())
            {
  
                try
                {
                    Stream data =
                        await httpClient.GetStreamAsync(
                            Urls.GetUrl(Urls.UrlType.Blogs));
                    List<TourDate> blogs = await Task.Run(() =>
                        GetBlogList(data));
                    return blogs;
                }
                catch (Exception ex)
                {
                    if (retries == 3)
                    {
                        throw;
                    }
                }


                retries = retries + 1;
                return await GetRecentBlogs();

  
            }
        }

Here is my current configuration.

Microsoft Visual Studio Ultimate 2013
Version 12.0.40121.00 Update 5 CTP
Microsoft .NET Framework
Version 4.5.51650

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0451013-02019
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2013   06181-004-0451013-02019
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06181-004-0451013-02019
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0451013-02019
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0451013-02019
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0451013-02019
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0451013-02019
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0451013-02019
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0451013-02019
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.302.0 (80f4e84)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 10 Russell Fustino 2015-02-20 12:48:30 UTC
Same thing is happening to me in the current release of Xamarin Forms and it used to work in a prior version (unless something changed on the web site I am trying to hit, will know that soon). I am getting a 302 on a redirect using this rss feed:

http://jethrotull.com/?feed=gigpress&artist=2

The request gets routed thru CloudFlare. I have been working with the Jethro Tull Webmaster and he has made some fixes for me with getting a 522 Timeout Request due to all the testing ( :) ) ... and now we are down to a 302. This is a show stopper right now, as these are the tour dates feed. The Jethro Tull App is almost ready to publish! So any work around would be greatly appreciated! Miss you all!

Here is my code and configuration:

        private int retries=0;  
        public async Task<List<TourDate>> GetRecentBlogs()
        {
       
            using (var httpClient = new HttpClient())
            {
  
                try
                {
                    Stream data =
                        await httpClient.GetStreamAsync(
                            Urls.GetUrl(Urls.UrlType.Blogs));
                    List<TourDate> blogs = await Task.Run(() =>
                        GetBlogList(data));
                    return blogs;
                }
                catch (Exception ex)
                {
                    if (retries == 3)
                    {
                        throw;
                    }
                }


                retries = retries + 1;
                return await GetRecentBlogs();

  
            }
        }

Here is my current configuration.

Microsoft Visual Studio Ultimate 2013
Version 12.0.40121.00 Update 5 CTP
Microsoft .NET Framework
Version 4.5.51650

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0451013-02019
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2013   06181-004-0451013-02019
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06181-004-0451013-02019
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0451013-02019
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0451013-02019
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0451013-02019
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0451013-02019
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0451013-02019
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0451013-02019
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.302.0 (80f4e84)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 11 PJ 2015-02-20 14:26:22 UTC
I can reproduce the issue with the test case you have provided, but the test case used to verify this bug (comment 7) still passes so I won't REOPEN. 

I've filed a new bug to track your variant of the case Russell, bug 27265. I'll add you to the CC there.