Я пытаюсь обновить код, который контролирует почтовый ящик 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 строках после второго Try (что фактически находится в методе 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- из-за-к-ан-неожиданного-пакеты формата) –