我到處搜索但沒有任何好處。使用VB.net下載文件不完整
我使用這個代碼來下載文件:
Imports System.IO
Imports System.Security.AccessControl
Imports System.Net
Imports System.ComponentModel
Public Class Step4
Function GetUserName() As String
If TypeOf My.User.CurrentPrincipal Is
System.Security.Principal.WindowsPrincipal Then
' The application is using Windows authentication.
' The name format is DOMAIN\USERNAME.
Dim parts() As String = Split(My.User.Name, "\")
Dim username As String = parts(1)
Return username
Else
' The application is using custom authentication.
Return My.User.Name
End If
End Function
Private Sub Step4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Code of Step3
Dim URL As String = "http://skinsserver.exampleserver.com/skins.zip"
Dim filename As String = "C:\Users\" + GetUserName() + "\AppData\Roaming\Applicationsettings\skins.zip"
Using wc As New WebClient
wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)")
wc.DownloadFile(URL, filename)
End Using
End Sub
End Class
我什麼都試過,但只有800文件的字節被下載而它是22 KB。
通過瀏覽器下載是好的。
請幫忙!
謝謝!
你可以發佈真實的網址,我們可以試試嗎? – Youssef13
我上傳了另一臺服務器上的相同文件,此代碼工作正常。但是,這是我必須使用的服務器,以任何方式解決這個問題? – MatrixCow08
即使在瀏覽器中,問題代碼中的鏈接也不起作用。 – Youssef13