从URL代码VB.NET下载文件

时间:2016-04-26 05:39:40

标签: vb.net file download

我想问一下,如何通过代码vb.net从url下载文件?
示例:Example Link 在下载文件之前,用户必须输入用户名和密码?我怎样才能做到这一点?任何参考或链接?谢谢!

1 个答案:

答案 0 :(得分:8)

使用System.Net.WebClient.DownloadFile

Dim remoteUri As String = "http://belajar123.com/materi.zip"
Dim fileName As String = "materi.zip"
Dim pasword As String = "..."
Dim username As String = "..."

Using (var client = new WebClient())

    client.Credentials = New NetworkCredential(username, password)
    client.DownloadFile(remoteUri, fileName)
End Using