我試圖更新監視Exchange Server郵箱的代碼,以便它可以使用SSL登錄。然而,當它試圖登錄時,我得到的錯誤:The handshake failed due to an unexpected packet format.
由於意外的數據包格式記錄到Pop3而導致握手失敗
我的連接代碼如下(有記錄和評論刪除):
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
try
{
tcpClient = new TcpClient(Host, Port);
}
catch (SocketException e) { ... }
try
{
var stream = client.GetStream();
ssl = new SslStream(stream);
ssl.AuthenticateAsClient(Host, null, SslProtocols.Tls, true);
streamReader = new StreamReader(ssl);
response = streamReader.ReadLine();
if (response.StartsWith("+OK"))
{
response = SendReceive("USER ", UserName.Trim() + "@" + Domain.Trim());
if (response.StartsWith("+OK"))
{
response = SendReceive("PASS ", Password);
}
}
if (response.StartsWith("+OK"))
result = true;
}
catch (Exception e) { ... }
從日誌記錄,我已經精確定位的例外在第二次嘗試之後的前4行中的某處(實際上在GetStreamReader方法中,但爲了簡潔和可讀性,我將它組合在一起)。
,我收到異常下面是:
--- Exception ---
Error: 3/8/2016 10:32:35 AM The handshake failed due to an unexpected packet format.
Info: 3/8/2016 10:32:35 AM There was an error connecting to the account.
The server returned
The handshake failed due to an unexpected packet format.
Info: 3/8/2016 10:32:35 AM Source: System
Info: 3/8/2016 10:32:35 AM Method: Void StartReadFrame(Byte[], Int32, System.Net.AsyncProtocolRequest)
Info: 3/8/2016 10:32:35 AM
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at POP3_Communication.Pop3.GetStreamReader(TcpClient client)
at POP3_Communication.Pop3.Connect()
可能重複的[System.IO.IOException:握手失敗,由於意外>數據包格式?](http://stackoverflow.com/questions/5178757/system-io-ioexception-the-handshake-failed-由於對一個-意想不到分組格式) –