views:

843

answers:

1

Download fails for authenticated sites. I've tried passing Network Credentials and allowing AutoRedirect but that doesnt work.

The application works fine for URLs that allow downloads with authentication. But my application has to download components from a site that requires authentication. So in a browser..the download url redirects to the authorisation window and then redirects back to the original domain with the dirct file download link and then the browser download-savefile-dialog opens. but in my application if send the credentials to the original download page, it doesnt throw any exception or say that the authentication worked or not, instead it downloads some random tiny file say about 0.05MB (the files im trying to download are atleast 50MB+)

Does anyone know what im doing wrong? or how i can see what is happening when my code executes?

 private HttpWebRequest hRequest;

 private HttpWebResponse hResponse;

NetworkCredential myCred = new NetworkCredential("[email protected]", "123random");

        CredentialCache myCache = new CredentialCache();

        myCache.Add(new Uri("domain"), "Basic", myCred);


hRequest = (HttpWebRequest)WebRequest.Create(tbURL.Text);

            hRequest.Credentials = myCache;

            hRequest.AllowAutoRedirect = true;


            //hRequest.Credentials = CredentialCache.DefaultCredentials;

            hResponse = (HttpWebResponse)hRequest.GetResponse();
A: 

Use Fiddler or HttpAnalyzer to see what actually goes on when you download the file with a browser. The server might require a certain referrer or some special cookie.

Jesper Palm