Download A Page With Winsock


This is a small example that will allow you to download a web page using the Winsock control. First make a new project. Then add three things, a text box, a command button, and of course the Winsock control. Add this to the command button:

Private Sub Command1_Click()
Winsock1.RemoteHost = "soft.net.uk/domain/vb/"
Winsock1.RemotePort = 80
Winsock1.Connect
End Sub

This in the Winsock Connect procedure:

Private Sub Winsock1.Connect()
Dim strCommand as String
Dim strWebPage as String
strWebPage = "http://www.soft.net.uk/domain/vb/index.html"
strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
strCommand = strCommand + "Accept: */*" + vbCrLf
strCommand = strCommand + "Accept: text/html" + vbCrLf
strCommand = strCommand + vbCrLf
Winsock1.SendData strCommand
End Sub

And this goes in the Winsocks DataArival procedure:

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim webData As String
Winsock1.GetData webData, vbString
Text1.Text = Text1.Text + webData
End Sub


Copyright © 1999, SeeT.