Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从网站下载zip文件时出错_Vb.net_Zipfile - Fatal编程技术网

Vb.net 从网站下载zip文件时出错

Vb.net 从网站下载zip文件时出错,vb.net,zipfile,Vb.net,Zipfile,我正在尝试使用web客户端从网站下载zip文件,但文件下载不正确 每次下载zip文件时,在目标目录中没有任何内容 下面我粘贴了我正在使用的代码: Imports System.Net Imports System.IO Imports System.Collections.Generic Imports System.Text Imports System.Net.NetworkInformation Imports System.Diagnostics Public Class Form

我正在尝试使用web客户端从网站下载zip文件,但文件下载不正确

每次下载zip文件时,在目标目录中没有任何内容

下面我粘贴了我正在使用的代码:

Imports System.Net
Imports System.IO
Imports System.Collections.Generic
Imports System.Text
Imports System.Net.NetworkInformation
Imports System.Diagnostics


 Public Class Form1
Private Sub _DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
    ' Update progress bar
    ProgressBar1.Value = e.ProgressPercentage
End Sub

Private Sub _DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
    ' File download completed
    Button1.Enabled = Enabled
    MessageBox.Show("Download completed")
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Button1.Enabled = False
    Dim ProcessingDate As Date = DateTime.Now
    Dim File2Download As String = "File Name To Be Downloaded.zip"
    Dim Url As String = "SourceURL" & File2Download 'http site
    Dim _WebClient As New System.Net.WebClient
    _WebClient.UseDefaultCredentials = True
    _WebClient.Headers("User-Agent") = "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; WOW64; Trident/5.0)"
    _WebClient.Headers("Method") = "GET"
    _WebClient.Headers("AllowAutoRedirect") = True
    _WebClient.Headers("KeepAlive") = True
    _WebClient.Headers("Accept") = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
    AddHandler _WebClient.DownloadFileCompleted, AddressOf _DownloadFileCompleted
    AddHandler _WebClient.DownloadProgressChanged, AddressOf _DownloadProgressChanged
    _WebClient.DownloadFileAsync(New Uri(Url), "Destination Directory\" & File2Download)
End Sub
End Class

我们诚恳地请求您在这方面的帮助。

您的
\u WebClient.Headers(“Accept”)=“text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”
表示您只准备接受html或xml文档。。。您可能希望将其更改为接受zip文件“application/zip,application/octet stream”

您使用的是实际的URL而不是
“SourceURL”
?你设置所有这些手动标题有什么原因吗?你的URL格式似乎是个问题。尝试将Url直接设置到适当的地址;某种形式的
Dim Url作为字符串=”http://someSite/directory/file.zip“
是的,我使用的是正确的源URL,而不是代码中的演示URL。我已分配这些手动标题,以假装来自web浏览器的请求,否则,我从网站上收到了403错误。现在403错误已经解决,但仍然没有有效的进展。