我在使用来自.NET Core 1.1 Web应用程序的HTTPS(TLS 1.2)对外部API进行HTTP调用时遇到问题。应用程序在本地运行正常,但在部署到Azure应用程序服务时,我得到以下异常:
exceptionMessage:An error occurred while sending the request.
exceptionType:System.Net.Http.HttpRequestException
内部例外是:
innerExceptionMessage:A security error occurred
innerExceptionType:System.Net.Http.WinHttpException
奇怪的是,我没有在外部API的所有请求上得到此异常,它只发生了一些时间。
我注意到其他SO帖子中已经讨论过类似的问题,但大多数都是关于自签名证书的。就我而言,远程服务器正在使用由GeoTrust签名的证书。
所有来电均以System.Net.Http.HttpClient
相关:
完整堆栈跟踪:
{ exceptionType: "System.Net.Http.HttpRequestException", innerException: { innerStacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()", innerExceptionMessage: "A security error occurred", innerExceptionType: "System.Net.Http.WinHttpException" }, stacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.ApiService.<PostResourceToApiAsync>d__5`1.MoveNext() in C:\projects\integration\src\Integration\Services\ApiService.cs:line 112 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<NotifyOwnerAsync>d__12.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 115 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<CreateAccountAsync>d__9.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 66 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.PartnerService.<CreateAccountAsync>d__11.MoveNext() in C:\projects\integration\src\Integration\Services\PartnerService.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Controllers.AccountsController.<Create>d__7.MoveNext() in C:\projects\integration\src\Integration\Controllers\AccountsController.cs:line 92 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()", exceptionMessage: "An error occurred while sending the request." }
答案 0 :(得分:0)
我认为我看到的问题是由于这个错误:https://github.com/dotnet/corefx/issues/7812
这就解释了为什么我只在应用程序部署到Azure中的Web应用程序时才看到这个,因为它运行的是Windows Server 2012.真正的解决方法是升级到Windows Server 2016,但目前不支持Azure中的网络应用程序: - (
我现在的解决方法只是一个简单的重试机制,似乎效果很好。