Nhu Nguyen
Nhu Nguyen

Reputation: 187

Get Http Response

I using Socket to get http response from www.google.com.vn

TcpClient c = new TcpClient();
IPAddress ip = IPAddress.Parse("74.125.128.94"); // www.google.com.vn
IPEndPoint remoteEP = new IPEndPoint(ip, 80);
c.Connect(remoteEP);
StreamReader sr = new StreamReader(c.GetStream());
String s = sr.ReadToEnd();
Console.WriteLine(s);

I do not get any results out. What's problem?

Upvotes: 0

Views: 661

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499660

You're not actually making a request - you're just connecting to the port.

Either write an HTTP request to the socket, or (preferrably) use WebRequest or WebClient so that you don't end up implementing an HTTP client yourself...

Upvotes: 6

Related Questions