我在用着WebBrowser control
浏览登录页面并下载文件。由于我找不到使用我正在使用的控件自动管理下载的方法WebClient
类来尝试实现这一目标。
问题是自从WebClient
与浏览器不在同一上下文/会话中,我下载的只是安全错误屏幕。
关于如何传递上下文的任何想法WebBrowser
会议到WebClient
?
经过一周的谷歌搜索尝试解决方案后,我发现一个非常简单的解决方案!
我想以静默方式下载 HTTPS URL 中的文件,而 Web 浏览器控件只需执行此操作。
1) 使用浏览器登录
2)使用此代码进行下载。
//build de URL
string _url = "https://........."
//define a download file name and location
string _filename = @"C:\Users\John\Documents\somefile.pdf";
//create a webcliente
WebClient cliente = new WebClient();
//do some magic here (pass the webbrowser cokies to the webclient)
cliente.Headers.Add(HttpRequestHeader.Cookie, webBrowser1.Document.Cookie);
//and just download the file
cliente.DownloadFile(_urlpdf, _filename);
它解决了我的问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)