收藏
回答

net core 3.1 通过code换取网页授权access_token和openid 报错?

net core 3.1 通过code换取网页授权access_token和openid   时候报错了

var url = $"https://api.weixin.qq.com/sns/jscode2session?appid={ _wechatConfigOptions.Value.ProcessAppId}&secret={ _wechatConfigOptions.Value.ProcessSecret}&js_code={code}&grant_type=authorization_code";

        public async Task<string> GetHttpAsync(string urladdress)

        {

            using (WebClient MyWebClient = new WebClient())

            {

                MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据

                Byte[] pageData = await MyWebClient.DownloadDataTaskAsync(new Uri(urladdress)); //从指定网站下载数据        

                return Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句

            }

        }

下面是错误

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

 ---> 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.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, 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.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

   at System.Net.HttpWebRequest.SendRequest()

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

   --- End of inner exception stack trace ---

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)

   at System.Net.WebClient.GetWebResponseTaskAsync(WebRequest request)

   at System.Net.WebClient.DownloadBitsAsync(WebRequest request, Stream writeStream, AsyncOperation asyncOp, Action`3 completionDelegate)

   at Sxl.Client.Web.Service.HttpService.GetHttpAsync(String urladdress) in C:\Users\Administrator\Desktop\Sxl.Client.Web\Sxl.Client.Web\Service\HttpService.cs:line 41

   at Sxl.Client.Web.Controllers.WeChatController.LoginMiniProcessAsync(String code) in

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

3 个回答

  • ……
    ……
    2022-06-01

    net core 3.1 通过code换取网页授权access_token和openid 

    报错

    2022-06-01
    有用 1
    回复
  • Jia
    Jia
    2021-12-15

    解决了吗?我也是遇到这个问题,偶尔报这个错误

    2021-12-15
    有用 1
    回复
  • 一路向北
    一路向北
    2021-08-10

    请问解决了么?我最近也遇到这个问题

    2021-08-10
    有用 1
    回复 4
    • 郝鹏
      郝鹏
      2021-08-11
      没有啊。不知道为啥。我用的https 接口。没有测过http
      2021-08-11
      回复
    • 郝鹏
      郝鹏
      2021-08-11回复郝鹏
      你试试我下面发表的,好像没有问题,你试试,。
      2021-08-11
      回复
    • 一路向北
      一路向北
      2021-08-16回复郝鹏
      好的,无解中,看别人的帖子说,跳过https认证部分。
      2021-08-16
      回复
    • 郝鹏
      郝鹏
      2021-09-01回复一路向北
      我做了测试。跳过https认证也报同样的错误,和这个认证没啥关系啊,这个错误是偶发性的错误,我感觉是不是我们的服务器上的网络,还是设备啥的不太稳定啊,真的无语了啊。。。
      2021-09-01
      回复
登录 后发表内容