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

问题描述

你好,



我想用C#下载zip文件。



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



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



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







在此行获取错误:

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

推荐答案


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

11-01 05:15