using System; using System.Net.Sockets; using System.IO; using System.Text; namespace httpClient { class client { const int BUF_SIZE = 1024; public string Get(string host, string path, int port, ref string res) { int lg; try { ASCIIEncoding a = new ASCIIEncoding(); TcpClient s = new TcpClient(host, port); NetworkStream n = s.GetStream(); string req = "GET " + path + " HTTP/1.1\r\nHost: " + host + "\r\n\r\n"; n.Write(a.GetBytes(req),0,req.Length); string head; // on ne gère que le texte ( pas les images ) StreamReader sr = new StreamReader(n); while ( (head = sr.ReadLine()).Length > 0 ) { res += head + "\r\n"; } res += "\r\n"; char[] buf = new char[BUF_SIZE]; while ( (lg = sr.Read(buf,0,BUF_SIZE)) > 0) res += new String(buf).Substring(0,lg).Replace("\n","\r\n") + "\r\n"; sr.Close(); } catch (Exception e ) { res = e.ToString(); } return res; } static void Main(string[] args) { (new Form1()).ShowDialog(); } } }