【问题标题】:Asp.Net Core: HttpRequestException on call to external APIAsp.Net Core:调用外部 API 时出现 HttpRequestException
【发布时间】:2017-12-07 15:30:04
【问题描述】:

我在使用 .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." }

【问题讨论】:

标签: azure asp.net-core tls1.2 asp.net-core-1.1


【解决方案1】:

我认为我看到的问题是由于这个错误:https://github.com/dotnet/corefx/issues/7812

这解释了为什么我只在将应用程序部署到 Azure 中的 Web 应用程序时才看到这一点,因为它正在运行 Windows Server 2012。对此的真正解决方法是升级到 Windows Server 2016,但目前不支持Azure 中的网络应用 :-(

我现在的解决方法只是一个简单的重试机制,它似乎工作得很好。

【讨论】:

    猜你喜欢
    • 2020-02-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 2018-09-13
    • 2014-10-02
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多