Bug 21545 - ModernHttpClient or System SendAsync fails for a specific URL
Summary: ModernHttpClient or System SendAsync fails for a specific URL
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-07-23 08:46 UTC by Mustafa Shaik
Modified: 2014-07-23 15:17 UTC (History)
3 users (show)

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

IOS & Win Console app (1.50 MB, application/zip)
2014-07-23 08:52 UTC, Mustafa Shaik

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:

Description Mustafa Shaik 2014-07-23 08:46:05 UTC

Comment 1 Mustafa Shaik 2014-07-23 08:51:13 UTC
When I use SendAsync of ModernHttpClient (1.1) or System.HttpClient to make an HTTP call for the API, https://tescostoreprefs.cloudapp.net:8080/storeprefs?clubcard=c1a0fcde6ea003cc9895ce0f1b9caded8bff043a, it crashes with the following call stack.

2014-07-23 18:10:29.090 CoreTest[55697:70b] SendAsync start...
2014-07-23 18:10:37.963 CoreTest[55697:70b] Exception Details: 
Message: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
Stacktrace:   at ModernHttpClient.AFNetworkHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
--- 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.Net.Http.HttpResponseMessage].GetResult () [0x00034] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59 
  at CoreTest.CoreTestViewController+<ExecuteQuery>c__async0.MoveNext () [0x000d3] in /Volumes/HDD/Samples/SendAsyncCoreTest/iOSCoreTest-Individual/CoreTest/CoreTestViewController.cs:43 

But when the System.Httpclient is invoked in Windows.Console app, it works fine. Please find the attached samples for both IOS & Windows Console app.

Mustafa Shaik
Comment 2 Mustafa Shaik 2014-07-23 08:52:59 UTC
Created attachment 7477 [details]
IOS & Win Console app

Unzip the folder. That shows 2 apps, IOS Sample and Windows Console App. The missing references can be picked from the lib folder on the same level.
Comment 3 Udham Singh 2014-07-23 11:05:16 UTC
I have checked this issue and getting the same behavior mentioned in comment 1. To checked this issue I have downloaded the sample app provided in comment 2, run the iOS app, debug the code and got the issue. Please refer the screencast : http://screencast.com/t/uQ12upu6

Environment Info : 

=== Xamarin Studio ===

Version 5.1.4 (build 0)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.4.0 ((no/954ed3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000214

=== Xamarin.Android ===

Version: 4.12.6 (Indie Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: (Indie Edition)
Hash: 87026b6
Build date: 2014-07-02 19:39:08-0400

=== Xamarin.Mac ===


=== Build Information ===

Release ID: 501040000
Git revision: 7d45bbe2ee22625f125d0c52548524f02d005cca
Build date: 2014-07-14 12:15:53-04
Xamarin addins: c78f1d88e57baa928aeee1484d96e6f8edf8de33

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 4 Sebastien Pouliot 2014-07-23 15:17:49 UTC
If I try to open this URL [1] in Safari I get an error that the SSL certificate is invalid - it's a self-signed certificate and the OS does not trust it.

That's very likely the reason for the "NSURLErrorDomain error -1012". By default Apple (or even .NET) does not allow you to download from untrusted web sites. Sadly Apple error code/description is not very helpful (the same code can be used for several reasons).

The right fix is to install a valid (trusted) certificate on the server. 

A workaround is possible (e.g. disable the check for testing) but should NOT be used in production.

[1] https://tescostoreprefs.cloudapp.net:8080/storeprefs?clubcard=c1a0fcde6ea003cc9895ce0f1b9caded8bff043a