简体   繁体   English

Webkit 是否在下载时显示文件保存对话框? 如何在 WebBrowser Control 中跳过?

[英]Does Webkit show file save dialog on download? How to skip in WebBrowser Control?

Hope you are doing good.希望你做得很好。

My requirement is to download some files from a site which requires login, password.我的要求是从需要登录名和密码的站点下载一些文件。 I am able to navigate through all the way to the file generation page.( using .Net webBrowser control ).我能够一直导航到文件生成页面。(使用 .Net webBrowser 控件)。 I am stuck at file save dialog.我被困在文件保存对话框中。 I want to skip it but unable to do so as the there is no direct link to the file to be downloaded.我想跳过它但无法这样做,因为没有指向要下载的文件的直接链接。 A function is called and the file is created on the fly.调用一个函数并动态创建文件。

I am considering to use something else than webBrowser .我正在考虑使用webBrowser以外的其他东西。 Please guide me, if webkit also shows the same file dialog?请指导我,如果 webkit 也显示相同的文件对话框? Is there a respectively easier way to skip that using webKit?是否有更简单的方法可以使用 webKit 跳过它?

I am using .Net 4.5 and windows 7 32 bit.我正在使用 .Net 4.5 和 Windows 7 32 位。

What i have already tried:我已经尝试过的:

SendKeys.WaitSend("{Enter}")

Result: Enter is sent to the webbrowser control, not to the file download dialog.结果: Enter 被发送到 webbrowser 控件,而不是文件下载对话框。 I have tried to get the process of the file dialog.我试图获取文件对话框的进程。 But Process "WindowsFormsApplication.vshost"** doesn't have any child processes.但是进程“WindowsFormsApplication.vshost”** 没有任何子进程。

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
WebClient client = new WebClient();
client.DownloadDataCompleted += new  DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
client.DownloadDataAsync(e.Url);

Result: e.URL has no direct link.结果: e.URL 没有直接链接。 On clicking the file for download, a function is called at back-end.单击要下载的文件时,会在后端调用一个函数。 I have seen in Firefox the code inside that function, which is just this one line:我在 Firefox 中看到了该函数内部的代码,只有这一行:

document.location.href = 'something.do?something='+variable1+'&something='+variable2+ '&something=' + variable3;

Investigating above, i am able to call that function directly by pasting the following line in browser.(in case my session has not expired):调查上面,我可以通过在浏览器中粘贴以下行来直接调用该函数。(如果我的会话没有过期):

https://something.com/downloadsomething.do?somevariable=45875&somenumber=54875125&somevariable=1Hg5422 https://something.com/downloadsomething.do?somevariable=45875&somenumber=54875125&somevariable=1Hg5422

and what i see next is a dialog box asking save/open/cancel.我接下来看到的是一个对话框,要求保存/打开/取消。

Thank You, Regards谢谢,问候

I have done it using pinvoke.我已经使用 pinvoke 完成了。 By bringing the save dialog window to front and then sending keys to it.通过将保存对话框窗口置于最前面,然后向其发送密钥。

IntPtr fileDownloadDialogPointer = FindWindow(null, "File Download");
SetForegroundWindow(fileDownloadDialogPointer);
SendKeys.SendWait("%s");

%s is for "Alt + S". %s 代表“Alt + S”。 After this, save as dialog will appear.之后,将出现另存为对话框。 Handling that too in the same way.也以同样的方式处理。 Thank You ALL谢谢你们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM