收藏
回答

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

.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();

回答关注问题邀请回答
收藏

4 个回答

  • 李天裕
    李天裕
    04-02

    我也遇到了相同的问题,core2.0升级到3.1后,这个错误出现的概率大约1%,我换一台服务器测试就没问题,所以应该不是代码的原因,应该是服务器配置的问题。目前猜测,应该是服务器安装的ASP.NET Core Runtime版本不对,需要升级(我暂时还没验证)。

    https://dotnet.microsoft.com/en-us/download/dotnet/3.1

    04-02
    有用
    回复
  • ㅤhl
    ㅤhl
    2021-09-02

    我想到个办法,失败的话再次调用接口,就可以了。

    2021-09-02
    有用
    回复
  • KeepYoung
    KeepYoung
    2021-08-09

    异常信息:

    The SSL connection could not be established, see inner exception.InnerExceptionMessage:Authentication failed because the remote party has closed the transport stream.

    我这跟你一样的问题,大佬解决了没有啊,跪求!!!

    2021-08-09
    有用
    回复 1
    • ㅤhl
      ㅤhl
      2021-08-31
      解决了吗
      2021-08-31
      回复
  • 豹富
    豹富
    2021-03-12

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

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

    2021-03-12
    有用
    回复 4
    • 妖精快跑
      妖精快跑
      发表于移动端
      2021-03-12
      微信没有返回错误,直接关闭传输流啊
      2021-03-12
      回复
    • 黎明破晓前
      黎明破晓前
      2021-03-20
      也遇到类似问题,批量推送的时候会出现
      2021-03-20
      回复
    • ㅤhl
      ㅤhl
      2021-08-03回复黎明破晓前
      怎么解决的啊,我也是不停调用这个接口,会出现
      2021-08-03
      回复
    • 一路向北
      一路向北
      2021-08-24
      解决了么?我也遇到这类问题,找了很多,还是没搞好,别人这样写,还没试了ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
      2021-08-24
      回复
登录 后发表内容
问题标签