如何从生成文件ID的网站下载文件下载? [英] How to download file from website that generated file id to download?

查看:91
本文介绍了如何从生成文件ID的网站下载文件下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web浏览器控件来下载URL动态生成文件的文件。首先,我必须上传pdf文件然后网站将pdf文件转换为excel转换过程网站生成URL包含文件ID后请求该URL网站动态创建文件然后保存对话框。如何处理这种类型的URL?



示例:我已经上传文件名:123.pdf



转换过程后,网站会生成网址:https:www.123.com/api/download/562362



然后,



当我点击该Url保存对话框时,下载的文件名将为123.xlsx



如何在不显示保存对话框的情况下下载文件? (我无法以编程方式下载。)



我尝试过:



I am using web browser control to download file where URL generate file dynamically. First, I have to upload pdf file then website converts the pdf file into excel after conversion process website generates URL contains file id after requesting that URL website create file dynamically and then save dialog comes. How to handle such type of URL?

Example : I have uploaded File name: 123.pdf

After conversion process webiste generates Url: https:www.123.com/api/download/562362

Then,

When I click on that Url save dialog comes and downloaded file name will be 123.xlsx

How to download the file without showing save dialog? (I m not able to download programmatically.)

What I have tried:

 Dim Download_link As String
    Dim FileName As String
    Dim Final_File_Name As String
    Dim savepath = Application.StartupPath & "\BACKUP\"
Private Sub Download_Click(sender As Object, e As EventArgs) Handles Download.Click
        For Each Ele As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
            If Ele.GetAttribute("InnerText").Contains("Click here to download it.") Then
                Dim s As String = Ele.GetAttribute("href")
                Download_link = s
                MsgBox(s)
                Dim FileName As String = Me.WebBrowser1.Document.GetElementById("file-field-label").InnerText
                Dim objReq As WebRequest = WebRequest.Create(Download_link)
                Dim objResp As WebResponse = objReq.GetResponse()
                Dim objStream As Stream = objResp.GetResponseStream()
                Dim reader As StreamReader = New StreamReader(objStream, Encoding.ASCII)
                Dim fStream As FileStream = New FileStream(savepath & FileName, FileMode.Create)
                Dim writer As StreamWriter = New StreamWriter(fStream)
                writer.Write(reader.ReadToEnd())
                objStream.Close()
                reader.Close()
                writer.Close()
                fStream.Close()
            End If
        Next
    End Sub

推荐答案

没有该对话框就无法下载,它是浏览器的安全功能。您需要以编程方式下载文件。您应该努力解决无法以编程方式解决问题的原因,而不是继续使用当前的解决方案。
You can't download without that dialog, it is a security feature of the browser. You will need to download the file programatically. Rather than continuing with your current solution you should work to fix the reason why you can't down it programatically.


这篇关于如何从生成文件ID的网站下载文件下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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