Доброго времени суток! ПРоблема такая, устанавливаю коннект через sslstream, авторизуюсь, а в результате получаю Bad Request Your client has issued a malformed or illegal request. Вот код: | Код | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using System.Net.Sockets; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Security.Authentication;
namespace SSL_Socks { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static bool ValidateServerCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true;
Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
return false; } public static void RunClient(string machineName, string serverName) { TcpClient s = new TcpClient(); s.Connect(machineName, 443); SslStream sslStream = new SslStream( s.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null ); try { sslStream.AuthenticateAsClient(serverName); } catch (AuthenticationException e) { Console.WriteLine("Exception: {0}", e.Message); if (e.InnerException != null) { Console.WriteLine("Inner exception: {0}", e.InnerException.Message); } Console.WriteLine("Authentication failed - closing the connection."); s.Close(); return; } string outStr = @"GET /accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl<mpl=plnch<mplcache=2 HTTP/1.0\r\n" + "Host: www.google.com \r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.40607)\r\n\r\n"; sslStream.Write(Encoding.ASCII.GetBytes(outStr)); byte[] inBuf = new byte[32 * 1024]; int inLen = 1; string response = string.Empty; while (inLen != 0) { inLen = sslStream.Read(inBuf, 0, inBuf.Length); response += Encoding.GetEncoding(1251).GetString(inBuf, 0, inLen); }
using (StreamWriter sr = new StreamWriter( @"c:\resp.htm", false, System.Text.Encoding.GetEncoding(1251))) { sr.WriteLine(response); } s.Close(); Console.WriteLine("Client closed."); }
private void button1_Click(object sender, EventArgs e) { RunClient("www.google.com", "www.google.com"); } } } |
В чем ошибка не могу понять, да и еще с Httpwebrequest проблем нет и получаю страницу и лоинюсь - все ок, но задача сделать подобное используя SSLStream Это сообщение отредактировал(а) papaP - 4.8.2006, 09:56
|