System
OS : Windows Server 2012 R2 Standard
.Net Core : 2.1.5
Problem
HTTPS address request, sometimes this error occurs, not every request will be wrong
The SSL connection could not be established, see inner exception.
Details
The SSL connection could not be established, see inner exception.
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Rookies.Pay.Infrastructure.HttpClientWrap.PostAsync(String url, String postData, IDictionary`2 headers, String contentType, Int32 timeout, Encoding encoding) in E:/...
Inner Exception:
Authentication failed, see inner exception.
Code:
```c#
public async Task
{
HttpResp resp = new HttpResp();
var client = _httpClientFactory.CreateClient();
if (headers != null)
{
foreach (KeyValuePair<string, string> header in headers)
{
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
if (timeout > 0)
{
client.Timeout = new TimeSpan(0, 0, timeout);
}
using (HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8))
{
if (contentType != null)
{
content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
}
using (HttpResponseMessage responseMessage = await client.PostAsync(url, content))
{
resp.StatusCode = responseMessage.StatusCode;
byte[] resultBytes = await responseMessage.Content.ReadAsByteArrayAsync();
resp.ResponseText = (encoding ?? Encoding.UTF8).GetString(resultBytes);
}
}
return resp;
}
```
What websites/URL's does this error occur with?
@davidsh > What websites/URL's does this error occur with?
Sorry for waiting so long to reply to you.
This error occurred when the URL was requested, but not every time, only occasionally
https://gateway.suhui.org/api/v1/order
Real bug: "see inner exception". Don't do that. Instead do
SslException(string message, Exception inner) : base(string_ssl_could_not_be_established + " " + inner.Message, inner)
@Rwing @joshudson i'm with the same issue and when i try to follow your link, i start getting more SSL error, any idea?
@caiogranero In my case, just simply set DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER to false everything is done.
Triage: Sadly, this is not actionable without a repro at this point.
There may have been improvements in .NET Core 3.0, so it is worth to try that.
We are working on improving SSL connection diagnostics, incl. considering changes to the exception (not 100% clear we're going to do that though) - @wfurt is now driving that effort actively.