.net core 3.1 服务器端获取用户信息经常出现Authentication failed?
发布于 5 年前 作者 zren 11957 次浏览 来自 官方Issues

.net core 3.1 服务器端获取用户信息经常出现

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

 —> System.IO.IOException: Authentication failed because the remote party has closed the transport stream.

   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)

— End of stack trace from previous location where exception was thrown —

   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)

   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

— End of stack trace from previous location where exception was thrown —

   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

   — End of inner exception stack trace —

   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)

   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)

   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

不是必然,是经常出现 ,请问是什么问题啊

请求代码

           var hander = new HttpClientHandler();

            hander.ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true;

          HttpClient webClient = new HttpClient(hander);

            var jsonString =

              await (await webClient.GetAsync(

              $“https://api.weixin.qq.com/sns/jscode2session?appid={SystemSetting.WeClientMiniAppID}&secret={SystemSetting.WeClientMiniAppSecret}&js_code={request.WeCode}&grant_type=authorization_code”

               )).Content.ReadAsStringAsync();

1 回复

后端接口详见https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html

前端只要保证传给你的code是新的,且没有任何接口使用过就行。

回到顶部