I have dozen apps that access api backend, but recently i was playing around with blank xamarin forms with netstandard 2 and i cant use hhtpclient to access backend....tried in two machines
var uri = "https://myurl";
var handler = new HttpClientHandler
{
Credentials = new NetworkCredential("user", "P@ssw0rd"),
UseDefaultCredentials = false
};
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("MATRICULA", "2147483647")
});
var client = new HttpClient(handler);
var response = await client.PostAsync(uri, formContent);
var text = await response.Content.ReadAsStringAsync();
Exception os postasync line
{System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception: at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00031] in :0
at System.Net.WebConnection.ReadDone (System.IAsyncResult result) [0x00056] in :0
at System.Threading.Tasks.TaskToApm+<>c__DisplayClass3_0.b__0 () [0x00000] in :0
at System.Threading.Tasks.AwaitTaskContinuation.InvokeAction (System.Object state) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x0001a] in :0
at System.Threading.Tasks.AwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x0000a] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x000b1] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (TResult result) [0x0003e] in :0
at Mono.Net.Security.MobileAuthenticatedStream+d__58.MoveNext () [0x001ee] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x0001c] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x00068] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x00000] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (TResult result) [0x00000] in :0
at Mono.Net.Security.AsyncProtocolRequest+d__23.MoveNext () [0x000dd] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x0001c] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x00068] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (TResult result) [0x0003e] in :0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (System.Threading.Tasks.Task1[TResult] completedTask) [0x00010] in :0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult () [0x00000] in :0
at Mono.Net.Security.AsyncProtocolRequest+d__24.MoveNext () [0x001d8] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x0001c] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x00068] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (TResult result) [0x0003e] in :0
at Mono.Net.Security.AsyncProtocolRequest+d__25.MoveNext () [0x00169] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x0001c] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x00068] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].SetResult (TResult result) [0x0003e] in :0
at Mono.Net.Security.MobileAuthenticatedStream+d__66.MoveNext () [0x0017c] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in :0
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x0001c] in :0
at System.Threading.Tasks.Task.FinishContinuations () [0x00068] in :0
at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
at System.Threading.Tasks.Task1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Threading.Tasks.TaskFactory1+FromAsyncTrimPromise1[TResult,TInstance].Complete (TInstance thisRef, System.Func3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x0000d] in :0
at System.Threading.Tasks.TaskFactory1+FromAsyncTrimPromise1[TResult,TInstance].CompleteFromAsyncResult (System.IAsyncResult asyncResult) [0x00073] in :0
at System.Net.Sockets.SocketAsyncResult+<>c.b__27_0 (System.Object state) [0x00000] in :0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00015] in :0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in :0
at ObjCRuntime.Runtime.ThreadPoolDispatcher (System.Func1[TResult] callback) [0x00006] in <b7935acd70e343049845d6fd73e5ec44>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00009] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00031] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System/System.Net/WebConnection.cs:439
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00059] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System/System.Net/HttpWebRequest.cs:1033
at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <cf9013b38a4e4129bd64785080dd2844>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at System.Net.Http.HttpClientHandler+d__64.MoveNext () [0x003d3] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:402
--- End of inner exception stack trace ---
at System.Net.Http.HttpClientHandler+d__64.MoveNext () [0x0046c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:406
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <cf9013b38a4e4129bd64785080dd2844>:0
at System.Net.Http.HttpClient+<SendAsyncWorker>d__48.MoveNext () [0x00080] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0
at App6.MainPage+d__1.MoveNext () [0x000b0] in C:\Users\gilbe\source\repos\App6\App6\App6\MainPage.xaml.cs:38 }
MobileAuthenticatedStream, I would assume you are trying to connect to a HTTPS/TLS 1.2 only site and have not set your build options for theNSURLSessionHTTPClient implementation and thus are still using the "old" / default Mono Managed provider that only supports TLS 1.0 - SushiHangover