下载文件时,Windows安全要求的臭名昭著尚未unaswered问题 [英] The notorious yet unaswered issue of downloading a file when windows security is required

查看:282
本文介绍了下载文件时,Windows安全要求的臭名昭著尚未unaswered问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个网站: http://site.domain.com 该凭据将提示窗口安全对话框。所以我设法使用WebBrowser控件来浏览网页和发送击键输入密码 - 我无法找到身边的另一种方式。

现在我来到那里的网站生成一个链接,我想下​​载一个文件来看,它看起来像:的 http://site.domain.com/operations/reporting/csv/Report720_2553217.csv

我尝试使用Web客户端来下载该文件,但它什么也不做(BR是我的WebBrowser控件):

  Web客户端WB =新的Web客户端();
wb.Headers.Add(br.Document.Cookie);
wb.DownloadFile(链接,@report.csv);
 

我一直在试图找到一个解决方案,工作无果。我知道web客户端未通过身份验证所以试图用网络浏览器的cookie,但它不工作。该Cookie如下所示:

TLTUID = 61FE48D8F9B910F9E930F42D6A03EAA6; TLTSID = 0B2B8EE82688102641B7E768807FA8B2; s_cc = TRUE; s_sq =%5B%5BB%5D%5D; ASPSESSIONIDQQSTRDQS = FNPJCODCEMGFIDHFLKDBEMHO

所以,我有两个问题:

  1. 如何让web客户端下载通过web浏览器会话中访问的文件。上述code样品中我究竟做错了什么?

  2. 有没有一种简单的方法来使用web浏览器只是下载并保存该文件以我选择的路径和文件名?或如何做到这一切使用Web客户端还是其他什么东西?

解决方案
  1. 不可能的,AFAIK。 Web客户端 web浏览器用不同层来访问网络。 Web客户端使用的 WinHTTP的 web浏览器使用的 URLMON 。因此,他们将有不同的会话(包括认证缓存)。

  2. 这是可能的,只是使用任何的 URLMON API来下载文件,例如: URLDownloadToFile URLDownloadToCacheFile 。我刚刚回答了一个类似的问题

在一个侧面说明,你不必在按键养活提供身份验证凭据。您可以实现 IAuthenticateEx 此web浏览器站点对象。这里是更多信息

There is a web site: http://site.domain.com which prompts for credentials with "windows security" dialog box. So I managed to use WebBrowser control to navigate to the page and send keystrokes to enter the password - I could not find another way around.

Now I came to the point where the website generates a link to a file I want to download, it looks like: http://site.domain.com/operations/reporting/csv/Report720_2553217.csv

I tried to use WebClient to download the file but it does nothing (br is my WebBrowser control):

WebClient wb = new WebClient();
wb.Headers.Add( br.Document.Cookie);
wb.DownloadFile(link, @"report.csv");

I have been trying to find a working solution to no avail. I know the web client is not authenticated so tried to use web browser's cookie but it does not work. The cookie looks as follows:

TLTUID=61FE48D8F9B910F9E930F42D6A03EAA6; TLTSID=0B2B8EE82688102641B7E768807FA8B2; s_cc=true; s_sq=%5B%5BB%5D%5D; ASPSESSIONIDQQSTRDQS=FNPJCODCEMGFIDHFLKDBEMHO

So I have two questions:

  1. How to allow web client to download a file accessible from web browser's session. What am I doing wrong in the above code sample?

  2. Is there an easy way to use WebBrowser solely to download and save that file to the path and filename of my choice? Or how to do it all using WebClient or something else?

解决方案

  1. Not possible, AFAIK. WebClient and WebBrowser use different layers to access web. WebClient uses WinHTTP, WebBrowser uses UrlMon. Thus, they would have separate sessions (including the authentication cache).

  2. That's possible, just use any of UrlMon APIs to download the file, e.g. URLDownloadToFile or URLDownloadToCacheFile. I've just answered a similar question.

On a side note, you don't have to feed in keystrokes to provide authentication credentials. You can implement IAuthenticateEx on WebBrowser site object for this. Here is more info.

这篇关于下载文件时,Windows安全要求的臭名昭著尚未unaswered问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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