如何处理GeckoFX中的文件下载?

时间:2020-12-17 13:55:17

I am using the latest GeckoFX 18 (hindlemail's fork) and have tried hard to achieve this simple method : Handle file downloads.

我正在使用最新的GeckoFX 18 (hindlemail's fork),并努力实现这个简单的方法:处理文件下载。

I want to know if there is a file download happening in the GeckoWebBrowser. There is no file download event, and even worse : clicking a link that leads to a file download doesn't trigger /any/ event. It just doesn't do nothing. No download dialog, no save file dialog, no url, no nothing.

我想知道GeckoWebBrowser是否有文件下载。没有文件下载事件,更糟糕的是:单击导致文件下载的链接不会触发/任何/事件。它什么都不做。没有下载对话框,没有保存文件对话框,没有url,什么都没有。

Is there a way I can handle file downloads ?

有没有一种方法我可以处理文件下载?

1 个解决方案

#1


2  

By using hindlemail's fork of geckofx you will have to handle LauncherDialog.Download event. This event has several parameters like url, filename, etc.

通过使用后路的geckofx的分支,您将不得不处理LauncherDialog。下载的事件。此事件有几个参数,如url、文件名等。

LauncherDialog.Download += LauncherDialog_Download;
////
void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    string filename = e.Filename; //do something with filename
    string url = e.Url; //use webclient to download file from this url
}

Even with this you will not be able to download files from secure sites like dropbox or facebook but it will download something, better than nothing. I don't know much about xul so I also has a hard time downloading files.

即便如此,你也无法从dropbox或facebook这样的安全网站上下载文件,但这总比什么都没有强。我不太了解xul,所以下载文件也很困难。

I tried this too:

我试着这个:

void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    WebBrowser ie = new WebBrowser();
    ie.Navigate(e.Url);
}

It will show Internet Explorer download file dialog if file can be downloaded that way. Probably cause of request headers or something. I also used Fiddler to find out what headers Firefox sends to server but I found nothing useful.

它将显示Internet Explorer下载文件对话框,如果文件可以通过这种方式下载。可能是由于请求头或其他原因。我还使用了Fiddler来查找Firefox发送到服务器的头文件,但是我发现没有什么有用的。

#1


2  

By using hindlemail's fork of geckofx you will have to handle LauncherDialog.Download event. This event has several parameters like url, filename, etc.

通过使用后路的geckofx的分支,您将不得不处理LauncherDialog。下载的事件。此事件有几个参数,如url、文件名等。

LauncherDialog.Download += LauncherDialog_Download;
////
void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    string filename = e.Filename; //do something with filename
    string url = e.Url; //use webclient to download file from this url
}

Even with this you will not be able to download files from secure sites like dropbox or facebook but it will download something, better than nothing. I don't know much about xul so I also has a hard time downloading files.

即便如此,你也无法从dropbox或facebook这样的安全网站上下载文件,但这总比什么都没有强。我不太了解xul,所以下载文件也很困难。

I tried this too:

我试着这个:

void LauncherDialog_Download(object sender, LauncherDialogEvent e)
{
    WebBrowser ie = new WebBrowser();
    ie.Navigate(e.Url);
}

It will show Internet Explorer download file dialog if file can be downloaded that way. Probably cause of request headers or something. I also used Fiddler to find out what headers Firefox sends to server but I found nothing useful.

它将显示Internet Explorer下载文件对话框,如果文件可以通过这种方式下载。可能是由于请求头或其他原因。我还使用了Fiddler来查找Firefox发送到服务器的头文件,但是我发现没有什么有用的。