Hello,
I've got a small application that tries to read HTML data without the
HTTPWebResponse and Request methods and I guess the server is closing
the connection after a while.
Here is my sample code:
----------------------------------------------------
IPHostEntry iphe=Dns.GetHostByName("www.google.com");
string ipString=iphe.AddressList[0].ToString();
TcpClient tcpClient=new TcpClient(ipString,80);
NetworkStream ns=tcpClient.GetStream();
StreamReader sr=new StreamReader(ns);
StreamWriter sw=new StreamWriter(ns);
sw.WriteLine("GET /\r\n\r\n");
string serverHtml=sr.ReadLine();
----------------------------------------------------
The problem is that sr.ReadLine() returns null after a while... since
I'm trying to access an "object null reference". Is there any problems
in the code above?
I tried also:
sw.WriteLine("GET /\n\n");
sw.WriteLine("GET / HTTP/1.1\r\nConnection: Keep-Alive\n\n");
sw.WriteLine("GET / HTTP/1.1\nConnection: Keep-Alive\n");
No results. The server never responds. Can anyone tell me what I'm
doing wrong?
Thanks in advance,
Nuno Magalhaes.