通过在C#中提交用户ID和密码从网站下载zip文件 [英] Download a zip file from a website by submitting userid and password in C#

查看:72
本文介绍了通过在C#中提交用户ID和密码从网站下载zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我想用C#下载zip文件。



C#代码应转至网页普氏市场中心 并输入用户名和密码,然后点击提交。



发布哪个,下一个页面将打开,因为我们有一个网格。代码应该点击45天列中的zip文件并下载zip文件。



带有屏幕截图的详细excel文件可以从下面的链接下载。



Platts_Data.xlsx



在此行获取错误:

Hello,

I would like to download the zip file using C#.

The C# code should go to web page Platts Market Center and enter user ID and password then click on submit.

Post which, the next page would open in that we have a grid. The code should click on the zip file in the "45 days column" and download the zip file.

The detailed excel file with screenshot can be downloaded from below link.

Platts_Data.xlsx

Getting error at this line :

wb.DownloadFile(downloadUri, destination);



错误消息=尝试了太多自动重定向。



谢谢,

Akash



我尝试了什么:




Error Message=Too many automatic redirections were attempted.

Thanks,
Akash

What I have tried:

    class Program
    {
        static void Main(string[] args)
        {
            string strDatetimestamp = DateTime.Now.ToUniversalTime().ToString("yyyy-mm-dd-hh-mm-ss");

            string LoginUrl = "https://pmc.platts.com/Login.aspx";
            string Referer = "https://pmc.platts.com/Login.aspx";
            string _userName = "abc@xyz.com"; // please change
            string _password = "abcdefghi"; // please change
            string downloadUri = "https://pmc.platts.com/MQT/MQTHandler.aspx?fn=Platts_Market_Data_BA_hist-" + strDatetimestamp + ".zip"; // please change
            string destination = Path.Combine(@"C:\", "Platts_Market_Data_BA_hist - " + strDatetimestamp + ".zip");  //please change
            string postData = String.Format("logonid={0}&logonpswd={1}&Log On=Log On", _userName, _password);

            string cookie = HTTHelper.ProcessLogin(postData, LoginUrl, Referer);

            WebClient wb = new WebClient();
            wb.Headers.Add(HttpRequestHeader.Cookie, cookie);
            wb.DownloadFile(downloadUri, destination);
        }
    }
}

推荐答案

WebClient类的凭据属性,其中包含身份验证。您需要使用中提供的用户凭据提供一些凭据。代码段



您的登录代码不安全,因为密码是通过网络发送 unencyrpted 。这是过去的完全失败。



如果这不起作用,你应该联系该网站的网站管理员。
The WebClient class has a Credentials property which handels authentication. You need to provide some credentials with that user credentials like provided in that code snippets.

Your logon code is unsecure because the password is send unencyrpted over the network. This is a total failure of the old days.

If that doesnt work you should contact the webmasters of that website.


这篇关于通过在C#中提交用户ID和密码从网站下载zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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