我正在尝试在HttpClient
上使用IHttpClientFactory
向.net core 2.2
发送请求,但收到如下的HttpRequestException
和SocketException
:>
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我尝试增加客户端超时时间,并保持活动连接,但是没有运气。 另外,我发现this问题仍然存在,但是我不确定我的问题是否与此相同,因为我在此本地服务器上没有任何高负载。
var request = new HttpRequestMessage(HttpMethod.Get, "https://jsonplaceholder.typicode.com/todos/1");
var client = _clientFactory.CreateClient("client");
client.Timeout = TimeSpan.FromSeconds(120);
client.DefaultRequestHeaders.ConnectionClose = false;
var response = client.SendAsync(request).Result;
在我的Startup.cs
中,我有:
services.AddHttpClient("client");