gpt4 book ai didi

c# - 进行 Http 调用时套接字异常

转载 作者:可可西里 更新时间:2023-11-01 16:35:36 27 4
gpt4 key购买 nike

我有一个由 App Service plan(S3) 托管的 blob 触发的 azure 函数 (v2)。该函数处理一个 json 文件并对 API 管理服务中公开的 API 进行Http 调用

我正在使用 HttpClient 进行 Http 调用。虽然这在具有相同设置的一个环境中工作正常,但在另一个环境中进行 http post 调用时失败。

异常:

System.Net.Sockets.SocketException with error message "The operation was canceled. Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request. The I/O operation has been aborted because of either a thread exit or an application request"

快速谷歌搜索告诉我,这可能是由于过多的 http 连接而发生的。此处有更多详细信息:

https://learn.microsoft.com/en-us/azure/azure-functions/manage-connections#connections-limit

解决方案是使用静态 HttpClient 或横向扩展 App 服务计划。我做了这两个只是为了意识到它仍然失败并出现相同的异常。

有人遇到过这个问题吗?

任何见解都会有所帮助。

编辑:这是进行http调用的代码

public class ReportingService : IReportingService
{
private static readonly HttpClient _httpClient = new HttpClient();
private readonly ILogger _logger;

public ReportingService(ILogger<ReportingService> logger, IConfigurationRoot configuration)
{
_logger = logger;
_httpClient.BaseAddress = new Uri(configuration["ReportingServiceBaseUrl"]);
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{configuration["APIUser"]}:{configuration["APIPassword"]}")));
}

public async Task<bool> RequestReport(string endpoint, StringContent httpContent)
{
try
{
var response = await _httpClient.PostAsync(endpoint, httpContent);
return response.IsSuccessStatusCode;
}
catch (Exception ex)
{
_logger.LogError(ex, "Migration failed");
throw;
}
}
}

最佳答案

从后端日志来看,只有执行,不幸的是失败了。

异常详情

时间戳:7/2/2019 6:49:55 AM内部异常类型:System.FormatException

Full Exception :
System.FormatException : Invalid blob path specified : ''. Blob identifiers must be in the format 'container/blob'.
at Microsoft.Azure.WebJobs.Host.Blobs.BlobPath.ParseAndValidate(String value,Boolean isContainerBinding) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\BlobPath.cs : 53
at Microsoft.Azure.WebJobs.Host.Blobs.Triggers.StringToCloudBlobConverter.ConvertAsync(String input,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Triggers\StringToCloudBlobConverter.cs : 21
at async Microsoft.Azure.WebJobs.Host.Blobs.BlobOutputConverter`1.TryConvertAsync[TInput](Object input,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\BlobOutputConverter.cs : 35
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Host.Converters.CompositeAsyncObjectToTypeConverter`1.TryConvertAsync[T](Object value,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Converters\CompositeAsyncObjectToTypeConverter.cs : 28
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Host.Blobs.Triggers.BlobTriggerBinding.BindAsync(Object value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Triggers\BlobTriggerBinding.cs : 158
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.TriggerWrapper.BindAsync(Object value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 475
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.cs : 57

如果您观察到任何 UTC 日期和时间,请告诉我

System.Net.Sockets.SocketException

关于c# - 进行 Http 调用时套接字异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com