Every Sunday and Friday new tutorials will be posted. This month will be Visual Basic .NET.
Sunday August 29, 2010 - Programatically Connecting to the Web with VB.NET.
The method we are going to be using is Wrapping. Click here to download the custom wrapper coded by Ricky that we will be using for this project. >>RickysWrapper.vb
1. Create a new VB.NET project and add two textboxes and one button as shown below
2. Import the wrapper by clicking Project > Add Existing Item or by alternatively pressing Shift + Alt + A, and locate the downloaded wrapper.
3. Double click the button to access it's code and add the following:
Dim wrapper As New RickysWrapper
Dim HTML As String
HTML = wrapper.GetRequest(TextBox1.Text, "http://www.google.com")
TextBox2.Text = HTML
Line 1: By creating the variable "wrapper" you are creating a new instance of RickysWrapper thus making it usable.
Line 2: We created another variable here, this is where the html of the specified page will be stored.
Line 3: The wrapper will attempt to connect to the website entered in TextBox1, and the refer will be http://www.google.com (refer is optional, you could just make it connect to the website.) The html will then be stored in the variable HTML
Line 4: The contents of the variable HTML will be shown in Textbox2
Step 5: Press F5 to run your program. Enter your URL in the first textbox then click the Connect button (remember to include "http://www.URL.com"
And that's it. You'll see that the HTML will be shown in Textbox2