AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

Downloading Web Pages with the Winsock Control

The Professional and Enterprise Editions of Visual Basic are shipped with the Winsock control.  This control allows you to use the low level Windows Sockets to connect to remote servers and execute commands or download Web pages.  This tip shows how to connect to a server and download a Web page.


You must have a Winsock control loaded into the project.  This code assumes the control is called Winsock1.  There also must be a text box on the form which is called txtWebPage.

First, connect to the remote computer using the following code:

Winsock1.RemoteHost = ""
Winsock1.RemotePort = 80

In the Winsock1.Connect event, place the following code to download the web page.

Dim strCommand as String
Dim strWebPage as String
strWebPage = ""
strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf 
strCommand = strCommand + "Accept: */*" + vbCrLf 
strCommand = strCommand + "Accept: text/html" + vbCrLf 
strCommand = strCommand + vbCrLf 
Winsock1.SendData strCommand      

The Winsock control will attempt to download the page.  When is receives some data from the server, it will trigger the DataArrival event.

Dim webData As String
Winsock1.GetData webData, vbString
TxtWebPage.Text = TxtWebPage.Text + webData




Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at