如何从直接链接以外的链接下载?

时间:2014-07-08 16:24:37

标签: vb.net winforms

我正在编译VB.NET中的一个程序,它从www.freeexampapers.com下载了一篇过去的论文(例如),但似乎我无法从看起来像这样的链接下载:" http://freeexampapers.com/index.php/directory/download?location=A%20Level/Biology/Edexcel/2001%20Jun/2001%20June%20Module%202B.pdf" 但是当我尝试从诸如"之类的直接链接下载时http://www.somewebsite.com/files/afile.file"有用。这是我的代码,所以请告诉我要纠正什么!非常感谢任何帮助(顺便说一下,我是VB.NET的初学者,所以我需要准确的答案和解释)

Public Class Form1
  Dim downloadsize As Long
  Dim Downloadedsize As Long
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim req As Net.HttpWebRequest
    Dim resp As Net.HttpWebResponse
    req = Net.HttpWebRequest.Create("http://freeexampapers.com/index.php/directory/download?location=A Level/Chemistry/Edexcel/2012 Jan/6CH08_01_msc_20120209.pdf")
    req.AllowAutoRedirect = True
    resp = req.GetResponse
    req.Method = Net.WebRequestMethods.Http.Get
    downloadsize = resp.ContentLength
    ProgressBar1.Maximum = downloadsize
    BackgroundWorker1.RunWorkerAsync()
    Timer1.Start()
End Sub

  Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    My.Computer.Network.DownloadFile("http://freeexampapers.com/index.php/directory/download?location=A Level/Chemistry/Edexcel/2012 Jan/6CH08_01_msc_20120209.pdf", "D:\edexcellogo.pdf", "", "", False, 60000, True)
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Downloadedsize = My.Computer.FileSystem.GetFileInfo("D:\pp.doc").Length
    ProgressBar1.Value = Downloadedsize
  End Sub
End Class

0 个答案:

没有答案