在会话WebBrowser控件下载文件 [英] WebBrowser Control download file in session

查看:152
本文介绍了在会话WebBrowser控件下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 WebBrowser控件浏览登录页面和下载文件。因为我无法找到一个方法来与我使用了 Web客户端类,试图实现这种控制系统自动管理下载。

I'm using WebBrowser control to navigate through a login page and download a file. Since I can't find a way to manage the download automatically with the control I'm using the WebClient class to try and achieve this.

但问题是,既然 Web客户端不在同一上下文/会话为所有的浏览器我是下载的安全错误的屏幕。

Problem is that since the WebClient isn't in the same context/session as the browser all i'm downloading is the Security Error screen.

我如何能够通过 web浏览器会话的上下文中的任何想法Web客户端

Any ideas on how I can pass the context of the WebBrowser session to the WebClient?

推荐答案

这应该是模拟在web浏览器会话和cookie和头的一个简单的事情重复使用这些假冒的Web客户端的会话,但它看起来像你再热已经该路径上。

It should be simply a matter of emulating the cookies and headers in the WebBrowser session and re-using them to impersonate the session in WebClient, but it looks like you're already hot on that path.

下面是我如何进行。

  1. 获取从web浏览器cookie和头。

饼干:您可以通过处理WebBrowser控件的DocumentCompleted事件,并分析从DocumentCompleted事件Cookie组从您的web浏览器会话中的Cookie

Cookies: You can get the cookies from your WebBrowser session by handling the DocumentCompleted event of the WebBrowser control and parsing the cookie set from DocumentCompleted event.

标题:使用像提琴手[www.fiddler2.com/]代理读取头,让您知道什么是必需的服务器

Headers: Use a proxy like Fiddler [www.fiddler2.com/] to read the headers so you'll know what's required by the server.

利用上述身份收集Web客户端。

标题:遍历你所有收集到的标题,并确保他们的添加到Web客户端使用 myWebClient.Headers.Add(内容类型,应用程序/ x-WWW的形式urlen codeD); 例如:

Headers: Iterate through all your collected headers and be sure they are added to the webclient using myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded"); for example

饼干:请参见这个帖子

这篇关于在会话WebBrowser控件下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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