c# - 如何使用 WebClient 登录到 "Flash Website"并使用 c# 下载文件?

标签 c# flash authentication webclient

我想登录网站并下载 .csv 文件,文件下载按钮位于第二个选项卡中。但是网站需要flash player。 这是我的尝试之一:

 public class CookieAwareWebClient : WebClient
    {
        private CookieContainer cookie = new CookieContainer();

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                (request as HttpWebRequest).CookieContainer = cookie;
            }
            return request;
        }
    }

var client = new CookieAwareWebClient();
        client.BaseAddress = @"https://example.com/";
        var loginData = new NameValueCollection();
        loginData.Add("username", "my user");
        loginData.Add("password", "my pwd");
        client.UploadValues("login/", "POST", loginData);

        string htmlSource = client.DownloadString("After login page");

结果:-

EXAMPLE

Welcome to example

Example is a reporting tool that tracks your music sales. This is where you can check how your releases are selling, update your account information and see quarterly/monthly statements. Information is updated in real time, so the numbers you are seeing are current.

Why am I Seeing This Page?

If you are seeing this page, you do not have Adobe Flash Player (version 9, or higher) installed to your browser, and/or you do not have javascript enabled. If you are still seeing this page after installing Adobe Flash Player, and have javascript enabled, please contact us at support@example.com

Get Adobe's Flash Player

© example, 2007

最佳答案

您不能使用简单的 WebClient 来做到这一点。

为了满足您的需求,我建议您使用带有 Selenium 和 Chrome 驱动程序的浏览器自动化。由于浏览器已经处理 flash,您只需要使用 Selenium 来导航并执行您想要的操作。

关于c# - 如何使用 WebClient 登录到 "Flash Website"并使用 c# 下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370826/

相关文章:

c# - 对象驻留在 c# 中的什么位置?

css - 如何将 StyleSheet 应用于纯文本的 TextField

ios - 如何编写代码来读取.fla 文件?

ruby-on-rails - rails : embed a flash swf

powershell - 使用 Power shell 登录 Power BI 会引发错误 "System.Net.WebException: The remote name could not be resolved: ' localhost.fiddler'"

PHP 登录使用 SHA1 连接到 MySQL 数据库

c# - 如何查看特定托管C#引用类型的内存大小和布局?

c# - 验证使用仅初始化 setter 初始化的 C# 对象

c# - 多个服务的多个组件

asp.net-mvc - ASP MVC Preview 5 和 IIS 6 Windows 身份验证