public static string Login() { IPHostEntry hostEntry = Dns.GetHostEntry("сайт"); IPAddress address = hostEntry.AddressList[0]; IPEndPoint ipe = new IPEndPoint(address, 80); Socket socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.Connect(ipe); if (socket.Connected) { Console.WriteLine("Connected to " + ipe.ToString()); } else { Console.WriteLine("Can not connect..."); } } catch (SocketException ex) { Console.WriteLine(ex.Message); } string request = "POST сайт HTTP/1.1\r\n" + "Accept: text/html\r\n" + "Host: сайт\r\n" + "Cookie: income=1\r\n" + "Referer: сайт\r\n"+ "Content-Length: " + "142" + "\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n\r\n" +"параметры"; Byte[] bytesSent = Encoding.ASCII.GetBytes(request); Byte[] bytesReceived = new Byte[1024]; socket.Send(bytesSent, bytesSent.Length, 0); string page = ""; int bytes = 0; do { bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0); page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes); } while (bytes > 0); return page; }
HTTP/1.1 302 Moved Temporarily X-Powered-By: Servlet/2.5 Server: Sun Java System Application Server 9.1_02 Set-Cookie: JSESSIONID=ac85e657399e7058ae4fd3fe2505; Path=/ Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Cache-Control: no-cache Cache-Control: no-store X-Powered-By: JSF/1.2 Location: сайт Content-Type: text/html; charset=iso-8859-1 Content-Length: 0 Date: Wed, 18 Feb 2009 19:06:40 GMT Connection: close