【问题标题】:HTTPS Call exception "The handshake failed due to an unexpected packet format."HTTPS 调用异常“由于意外的数据包格式,握手失败。”
【发布时间】:2020-10-22 08:37:59
【问题描述】:

在从 Windows 服务进行 REST api 调用(使用 https 方案)时,我收到异常,指出“由于意外的数据包格式,握手失败。”。将域用户分配为服务登录帐户后,上述异常就会消失。

另外,在开发阶段(Visual Studio 2015,C#)我没有遇到任何异常。

***Code Snippet:***
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 HttpClient Client = new HttpClient();
 var response = await Client.PostAsync("https://auth.brivo.com/oauth/token", httpContent, cancellationToken).ConfigureAwait(false);

***Exception Thrown:***
System.Net.Http.HttpRequestException occurred
  HResult=-2146233088
  Message=An error occurred while sending the request.
  Source=mscorlib
  StackTrace:
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at Sisco.FastPass.AccessControl.Brivo.HttpClientHelper.<PostFormDataRequest>d__5`2.MoveNext()
  InnerException: 
       HResult=-2146233079
       Message=The underlying connection was closed: An unexpected error occurred on a send.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
            at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
       InnerException: 
            HResult=-2146232800
            Message=**The handshake failed due to an unexpected packet format.**
            Source=System
            StackTrace:
                 at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
                 at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
                 at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
            InnerException: 

【问题讨论】:

    标签: c# https windows-services


    【解决方案1】:

    请参考以下链接并检查启用 ssl 协议部分: https://www.limilabs.com/blog/the-handshake-failed-due-to-an-unexpected-packet-format

    【讨论】:

      猜你喜欢
      • 2017-12-25
      • 2011-07-07
      • 2021-10-27
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多