Web page gets cut off

mjb3030

Well-known member
Joined
Aug 14, 2003
Messages
76
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:

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)
 
Make things easier by using the WebClient class for this.

I typically do something like this (in C#):
Code:
WebClient wc = new WebClient();
byte[] buffer = wc.DownloadData( @"http://www.cnn.com" );

return System.Text.ASCIIEncoding.ASCII.GetString( buffer );
 

Similar threads

S
Replies
0
Views
88
Specter FXX-K
S
L
Replies
0
Views
70
lifeisshort
L
V
Replies
0
Views
59
Virtualgamer22
V
M
Replies
0
Views
64
Markus Freitag
M
Back
Top