Read the source code from the web page and write it to the file.
Source: Internet
Author: User
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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.