Bug 28287 - WebException.Response is null under Mono, not null under .net
Summary: WebException.Response is null under Mono, not null under .net
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.10.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-21 01:37 UTC by dj_technohead
Modified: 2017-09-22 21:21 UTC (History)
5 users (show)

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


Attachments

Description dj_technohead 2015-03-21 01:37:37 UTC
With the following code:

  HttpWebRequest request = (HttpWebRequest)WebRequest.CreateHttp(url);
            if (Helpers.Proxy != null) request.Proxy = Helpers.Proxy;

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add("Content-Range: bytes */*");
            request.ContentLength = 0;
            request.Headers = headers;
            request.Method = "PUT";
            request.KeepAlive = false;

            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)(request.GetResponse());
                Debug.WriteLine(((HttpWebResponse)response).StatusDescription);
            }
            catch (WebException e)
            {
                Debug.WriteLine(e.Message);
                response = (HttpWebResponse)e.Response;
            }

when run under Windows (.net) and an (expected) WebException occurs:

{"The remote server returned an error: (308) Resume Incomplete."}
    base: {"The remote server returned an error: (308) Resume Incomplete."}
    Response: {System.Net.HttpWebResponse}
    Status: ProtocolError

Running the same under mono:

{System.Net.WebException: Invalid status code: 308 ---> System.Net.ProtocolViolationException: Invalid status code: 308
  at System.Net.HttpWebRequest.Redirect (System.Net.WebAsyncResult result, HttpStatusCode code, System.Net.WebResponse response) [0x000e9] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1138 
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0026d] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1691 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00165] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1485 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:969 
  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:985 
  at RedCorners.Vimeo.VimeoClient.Verify (System.String url) [0x00053] in /Users/dj_technohead/Projects/HighSeas/Specialus/Mobile/Framework/Vimeo/VimeoLowLevel.cs:56 }
	Data: Count=0
	HResult: -2146233079
	HelpLink: (null)
	InnerException: {System.Net.ProtocolViolationException: Invalid status code: 308
  at System.Net.HttpWebRequest.Redirect (System.Net.WebAsyncResult result, HttpStatusCode code, System.Net.WebResponse response) [0x000e9] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1138 
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0026d] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1691 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00165] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1485 }
	Message: "Invalid status code: 308"
	Response: (null)
	Source: "System"
	StackTrace: "  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:969 \n  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:985 \n  at RedCorners.Vimeo.VimeoClient.Verify (System.String url) [0x00053] in /Users/dj_technohead/Projects/HighSeas/Specialus/Mobile/Framework/Vimeo/VimeoLowLevel.cs:56 "
	Status: System.Net.WebExceptionStatus.ProtocolError
	TargetSite: {System.Net.WebResponse EndGetResponse(System.IAsyncResult)}
	Static members: 
	Non-public members:


In the case of .net, the WebException.Response object is not null, but under mono it is null.
Comment 1 dj_technohead 2015-05-12 18:18:32 UTC
Is there any progress on this? This is a pretty bad bug IMO. I've reproduced it going against YouTube as well. Both services use a status code HTTP 308 (Resume Incomplete) to inform the client how many bytes are left for the upload.
Comment 2 dj_technohead 2015-05-12 18:23:48 UTC
It seems like all that needs to be done is to return the HttpResponse in the WebException.Response.
Comment 3 juanjo.a 2017-03-03 12:00:01 UTC
Why don't you fix this bug? it was reported almost 2 years ago. 

Some services like Youtube or Google Drive use 308 responses for partial uploads and this bug is blocking Xamarin applications from using it. 

It also should be really easy to fix, just include the server response in WebException.Response like .NET Framework does.
Comment 4 Marek Safar 2017-03-09 15:23:35 UTC
What url are you using to test this?
Comment 5 juanjo.a 2017-03-09 18:27:33 UTC
For example, uploading files in multiple chunks to Google Drive using their API:

https://developers.google.com/drive/v3/web/resumable-upload
Comment 6 Paul Kiar 2017-09-22 21:21:27 UTC
If you use HttpWebRequest you can set HttpWebRequest.AllowAutoRedirect to false to avoid this exception. I haven't tried HttpClient.AllowAutoRedirect but it may work.

Note You need to log in before you can comment on or make changes to this bug.