Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);

Error Message=Too many automatic redirections were attempted.

Thanks,
Akash

What I have tried:

C#
    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);
        }
    }
}
Posted
Updated 21-May-19 6:16am
v2
Comments
lmoelleb 21-May-19 5:08am    
Don't just throw a bunch of code here and expect people to do your work. Use the debugger, isolate the line where the result is not what you expect. Then spend time trying to figure out why it behaves as it is doing. Once you have done that, update this question. be specific on what you expect to happen and what actually happens on the line where it goes wrong. If you do not know how to debug, learn it. Programming without debugging is a waste of time.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900