使用netstandard 2

时间:2018-03-20 05:26:34

标签: xamarin xamarin.forms

我有几十个访问api后端的应用程序,但最近我用netstandard 2玩空白xamarin表单,我无法使用hhtpclient访问后端....在两台机器上试过

 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();

异常os postasync行

{System.Net.Http.HttpRequestException:发送请求时发生错误---&gt; System.Net.WebException:获取响应流时出错(ReadDone2):ReceiveFailure ---&gt; System.Exception:在System.Net.WebConnection.HandleError(System.Net.WebExceptionStatus st,System.Exception e,System.String where)[0x00031] in:0   在System.Net.WebConnection.ReadDone(System.IAsyncResult result)[0x00056] in:0   在System.Threading.Tasks.TaskToApm +&lt;&gt; c__DisplayClass3_0.b__0()[0x00000] in:0   在System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(System.Object state)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback回调,System.Object状态,System.Threading.Tasks.Task&amp; currentTask)[0x0001a] in:0   在System.Threading.Tasks.AwaitTaskContinuation.Run(System.Threading.Tasks.Task任务,System.Boolean canInlineContinuationTask)[0x0000a] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x000b1] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1 [TResult] .SetResult(TResult result)[0x0003e] in:0   在Mono.Net.Security.MobileAuthenticatedStream + d__58.MoveNext()[0x001ee] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext(System.Object stateMachine)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run()[0x00024] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action,System.Boolean allowInlining,System.Threading.Tasks.Task&amp; currentTask)[0x0001c] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x00068] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x00000] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1 [TResult] .SetResult(TResult result)[0x00000] in:0   在Mono.Net.Security.AsyncProtocolRequest + d__23.MoveNext()[0x000dd] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext(System.Object stateMachine)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run()[0x00024] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action,System.Boolean allowInlining,System.Threading.Tasks.Task&amp; currentTask)[0x0001c] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x00068] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1 [TResult] .SetResult(TResult result)[0x0003e] in:0   在System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1[TResult].SetResult (System.Threading.Tasks.Task 1 [TResult] completedTask)[0x00010] in:0   在System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()[0x00000] in:0   在Mono.Net.Security.AsyncProtocolRequest + d__24.MoveNext()[0x001d8] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext(System.Object stateMachine)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run()[0x00024] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action,System.Boolean allowInlining,System.Threading.Tasks.Task&amp; currentTask)[0x0001c] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x00068] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1 [TResult] .SetResult(TResult result)[0x0003e] in:0   在Mono.Net.Security.AsyncProtocolRequest + d__25.MoveNext()[0x00169] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext(System.Object stateMachine)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run()[0x00024] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action,System.Boolean allowInlining,System.Threading.Tasks.Task&amp; currentTask)[0x0001c] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x00068] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1 [TResult] .SetResult(TResult result)[0x0003e] in:0   在Mono.Net.Security.MobileAuthenticatedStream + d__66.MoveNext()[0x0017c] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext(System.Object stateMachine)[0x00000] in:0   在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,System.Object state,System.Boolean preserveSyncCtx)[0x00071] in:0   在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback回调,System.Object状态,System.Boolean preserveSyncCtx)[0x00000] in:0   在System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run()[0x00024] in:0   在System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action,System.Boolean allowInlining,System.Threading.Tasks.Task&amp; currentTask)[0x0001c] in:0   在System.Threading.Tasks.Task.FinishContinuations()[0x00068] in:0   在System.Threading.Tasks.Task.FinishStageThree()[0x0003c] in:0   在System.Threading.Tasks.Task 1[TResult].TrySetResult (TResult result) [0x0004f] in <cf9013b38a4e4129bd64785080dd2844>:0 at System.Threading.Tasks.TaskFactory 1 + FromAsyncTrimPromise 1[TResult,TInstance].Complete (TInstance thisRef, System.Func 3 [T1,T2,TResult] endMethod,System.IAsyncResult asyncResult,System.Boolean requiresSynchronization)[0x0000d] in:0   在System.Threading.Tasks.TaskFactory 1+FromAsyncTrimPromise 1 [TResult,TInstance] .CompleteFromAsyncResult(System.IAsyncResult asyncResult)[0x00073] in:0   在System.Net.Sockets.SocketAsyncResult +&lt;&gt; c.b__27_0(System.Object state)[0x00000] in:0   在System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()[0x00015] in:0   在System.Threading.ThreadPoolWorkQueue.Dispatch()[0x00074]中:0   at ObjCRuntime.Runtime.ThreadPoolDispatcher(System.Func 1[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.TaskFactory 1 [TResult] .FromAsyncCoreLogic(System.IAsyncResult iar,System.Func 2[T,TResult] endFunction, System.Action 1 [T] endAction,System.Threading.Tasks.Task {{ 1}} 1 + ConfiguredTaskAwaiter [TResult] .GetResult()[0x00000] in:0   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x003d3] /System.Net.Http/HttpClientHandler.cs:402    ---内部异常堆栈跟踪结束---   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x0046c] /System.Net.Http/HttpClientHandler.cs:406 ---从抛出异常的先前位置开始的堆栈跟踪结束---   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c]中/exceptionservices/exceptionservicescommon.cs:152   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156   在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128   在System.Runtime.CompilerServices.ConfiguredTaskAwaitable 1[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.ConfiguredTaskAwaitable 1 [TResult] .GetResult()[0x00000] in:0   在App6.MainPage + d__1.MoveNext()[0x000b0]在C:\ Users \ gilbe \ source \ repos \ App6 \ App6 \ App6 \ MainPage.xaml.cs:38}

1 个答案:

答案 0 :(得分:0)

转到Android visual studio项目属性。然后转到Android选项,然后进入高级(在底部),然后执行HttpClient并从列表中选择Android。

相关问题