I am trying to retrieve a web page using tcpclient. It works, but if the page is very long, it always gets cut off. For example, I can receive the full page for www.google.com, but if I retrieve a google search page, the server disconnects halfway through and I only get half the page. Here is my code:
What should I be doing differently? (Besides eliminating the infinite DoEvents loop)
Code:
client = New TcpClient
client.Connect(txtURL.Text, 80)
stream = client.GetStream
Dim send() As Byte = Encoding.ASCII.GetBytes("GET / HTTP/1.0" & vbCrLf & _
vbCrLf)
stream.Write(send, 0, send.Length)
Dim recv(client.ReceiveBufferSize) As Byte
While Not stream.DataAvailable
Application.DoEvents()
End While
While stream.DataAvailable
stream.Read(recv, 0, client.ReceiveBufferSize)
Dim s As String = Encoding.ASCII.GetString(recv)
TextBox1.Text = TextBox1.Text & s
End While
What should I be doing differently? (Besides eliminating the infinite DoEvents loop)