README.md

December 4, 2022 ยท View on GitHub

Downloading HTTP with VB.NET

Description

Explains how to download http with VB.NET, includes a simple example.

More Info

Submitted On
ByLarry Bray
LevelIntermediate
User Rating4.0 (24 globes from 6 users)
CompatibilityVB.NET
CategoryInternet/ Browsers/ HTML
World.Net (C#, VB.net)
Archive File

Source Code



Downloading using HTTP with VB.NET is a fairly simple task. It really only takes four steps:

1 - Use the Create method of the System.Net.WebRequest class to specify the web page. This method will return a HttpWebRequest if the web page is http://, it will return a FileWebRequest if the web page is file://.
2 - Use the GetResponse method of the WebRequest object and return a WebResponse object for the web page.
3 - Create a StreamReader or BinaryReader depending on the type of data to be downloaded.
4 - The specifics that you need to perform on the stream.

The following example simply displays the html of a web page -

First, import System.Net and System.IO

Public Module Download
 Public Sub Main()
 Dim PgReq As HttpWebRequest = CType(WebRequest.Create(http://www.yahoo.com/index.html), HttpWebRequest)
 Dim PgResp As WebResponse = PageRequest.GetResponse()
 Dim sr As New StreamReader(PgResp.GetResponseStream())
 Dim Pg As String = sr.ReadToEnd()
 sr.Close()
 Console.Write(Pg)
 Console.ReadLine()
 End Sub
End Module