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

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

问题描述

有一个网站:http://site.domain.com 提示输入windows安全"对话框.所以我设法使用 WebBrowser 控件导航到页面并发送按键输入密码 - 我找不到其他方法.

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.

现在我到了网站生成一个指向我要下载的文件的链接的地步,它看起来像:http://site.domain.com/operations/reporting/csv/Report720_2553217.csv

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

我尝试使用 WebClient 下载文件但它什么也没做(br 是我的 WebBrowser 控件):

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");

我一直试图找到一个可行的解决方案,但无济于事.我知道 Web 客户端未经过身份验证,因此尝试使用 Web 浏览器的 cookie 但它不起作用.cookie 如下所示:

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=真;s_sq=%5B%5BB%5D%5D;ASPSESSIONIDQQSTRDQS=FNPJCODCEMGFIDHFLKDBEMHO

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

所以我有两个问题:

  1. 如何允许 Web 客户端下载可从 Web 浏览器会话访问的文件.我在上面的代码示例中做错了什么?

  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?

是否有一种简单的方法可以单独使用 WebBrowser 下载该文件并将其保存到我选择的路径和文件名?或者如何使用 WebClient 或其他方式完成所有操作?

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. 不可能,AFAIK.WebClientWebBrowser 使用不同的层来访问 web.WebClient 使用 WinHTTPWebBrowser 使用 UrlMon.因此,它们将具有单独的会话(包括身份验证缓存).

  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).

这是可能的,只需使用 UrlMon API 下载文件,例如URLDownloadToFileURLDownloadToCacheFile.我刚刚回答了一个类似问题.

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.

顺便提一下,您不必输入击键来提供身份验证凭据.您可以在 IAuthenticateEx 上实施<代码>WebBrowser 站点对象.这是更多信息.

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 安全性时下载文件的臭名昭著但未解决的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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