如何从VB.NET中的直接链接以外的链接下载? [英] How to download from links other than direct links in VB.NET?

查看:109
本文介绍了如何从VB.NET中的直接链接以外的链接下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



I am compiling a program in VB.NET which downloads a past-paper (for example) from www.xyz.com but it seems that I cannot download from the link which appears to be like this: " http://xyz.com/index.php/directory/download?location=A%20Level/Biology/Edexcel/2001%20Jun/2001%20June%20Module%202B.pdf " but when I try to download from a direct link such as " http://www.somewebsite.com/files/afile.file " it works. Here is my code, so please tell me what to correct! Any help is greatly appreciated ( btw I am a beginner in VB.NET, so I need exact answers with explanations please)

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://xyz.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://xyz.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

推荐答案

这篇关于如何从VB.NET中的直接链接以外的链接下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆