Private Sub DownloadData (ByVal URLString As String, ByVal LocalFile As String) 'localfile is a full path of the file (including *. exe)
Try
The 'httpwebrequest class provides support for attributes and methods defined in webrequests', and supports additional attributes and methods that allow users to directly interact with servers using HTTP.
Dim httpReq As System. Net. HttpWebRequest
The 'httpwebresponse class is used to generate an HTTP independent client application that sends HTTP requests and receives HTTP response.
Dim httpResp As System. Net. HttpWebResponse
Dim httpURL As New System. Uri (URLString)
HttpReq = CType (WebRequest. Create (httpURL), HttpWebRequest)
HttpReq. Method = "GET"
HttpResp = CType (httpReq. GetResponse (), HttpWebResponse)
Dim reader As StreamReader = New StreamReader (httpResp. GetResponseStream) 'if it is Chinese, set the encoding format to "GB2312 ".
Dim respHTML As String = reader. ReadToEnd () 'resphtml is the webpage source code
Dim Sw As StreamWriter = File. CreateText (LocalFile)
Sw. Write (respHTML)
Sw. Close ()
HttpResp. Close ()
Catch e As Exception
Console. WriteLine ("GetSource error: {0}, {1}", e. Message, URLString)
End Try
End Sub