从URL代码VB.NET下载文件

Chr*_* S. 2 vb.net file download

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

Cla*_*ius 8

使用 System.Net.WebClient.DownloadFile

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

Using client as new WebClient()

    client.Credentials = New NetworkCredential(username, password)
    client.DownloadFile(remoteUri, fileName)
End Using
Run Code Online (Sandbox Code Playgroud)

  • 在第6行上似乎有一些看起来像C#的代码(在开头的“使用”语句中)。我认为应该是“将客户端用作新的WebClient()”。 (3认同)