C# HTTPS呼叫异常“;由于意外的数据包格式,握手失败。”;
在从windows服务进行REST api调用(使用https方案)时,我遇到了一个异常,状态为“由于意外的数据包格式,握手失败”。在将域用户指定为服务登录帐户时,上述异常就会消失。 此外,在开发阶段(VisualStudio2015,C#)我也没有得到任何例外C# HTTPS呼叫异常“;由于意外的数据包格式,握手失败。”;,c#,https,windows-services,C#,Https,Windows Services,在从windows服务进行REST api调用(使用https方案)时,我遇到了一个异常,状态为“由于意外的数据包格式,握手失败”。在将域用户指定为服务登录帐户时,上述异常就会消失。 此外,在开发阶段(VisualStudio2015,C#)我也没有得到任何例外 ***代码段:*** ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12; HttpClient=新的HttpClient(); var response=w
***代码段:***
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12;
HttpClient=新的HttpClient();
var response=wait Client.PostAsync(“https://auth.brivo.com/oauth/token,httpContent,cancellationToken)。配置等待(false);
***引发异常:***
System.Net.Http.HttpRequestException发生
HResult=-2146233088
Message=发送请求时出错。
Source=mscorlib
堆栈跟踪:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()中
在Sisco.FastPass.AccessControl.Brivo.HttpClientHelper.d_u5`2.MoveNext()中
内部异常:
HResult=-2146233079
Message=基础连接已关闭:发送时发生意外错误。
来源=系统
堆栈跟踪:
位于System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult、TransportContext和context)
位于System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
内部异常:
HResult=-2146232800
Message=**由于意外的数据包格式,握手失败**
来源=系统
堆栈跟踪:
在System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)中
在System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)中
位于System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
内部异常:
如下所示参考此链接并选中启用ssl协议部分:
***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: