Visual studio 2017 HttpClient Get或Post不';不能使用.NETCore 2.1和2.2,但可以使用.NETCore 2.0

Visual studio 2017 HttpClient Get或Post不';不能使用.NETCore 2.1和2.2,但可以使用.NETCore 2.0,visual-studio-2017,asp.net-core-2.1,Visual Studio 2017,Asp.net Core 2.1,我使用Visual Studio 2017 v15.9.4、.NET标准2.0.3和.NETCore 2.1.6的最新版本。我在Windows 10 64位上运行我的应用程序 此代码: using (HttpClient client = new HttpClient()) { try { var response = await client.GetAsync("h

我使用Visual Studio 2017 v15.9.4、.NET标准2.0.3和.NETCore 2.1.6的最新版本。我在Windows 10 64位上运行我的应用程序

此代码:

 using (HttpClient client = new HttpClient())
            {
                try
                {
                    var response = await client.GetAsync("http://httpbin.org/")
                ...
不适用于.NET Core 2.1或2.2的最新版本。 我有一个例外:

Result StackTrace:  
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at EliorNugetCommon.Tests.APIManagerTests.Get() in D:\Git\Elior-Group\WebApiServices\NugetWAS\EliorNugetCommon\EliorNugetCommon.Tests\APIManagerTests.cs:line 50
----- Inner Stack Trace -----
Result Message: 
System.AggregateException : One or more errors occurred. (A task was canceled.)
---- System.Threading.Tasks.TaskCanceledException : A task was canceled.
但是,这适用于.NETCore2.0.9


感谢您的帮助。

使用.NET Core和.NET Core 2.2中的新HTTP堆栈,可以在代理后使用身份验证进行回归。在这种情况下,我们可以使用.NET Core 2.0 HTTP堆栈来切换:

AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

有关更多信息,请参见此处的讨论:

您是否打了多个电话?只是出于好奇。尝试使Get调用同步。(仅限故障排除步骤)只有外部呼叫失败。如果.NETCore2.1和2.2不使用代理,现在怎么办?