I have a WebClient object and am using the DownloadFileAsync method to get a file, although before I can I'm needing to log into the site, which seems to be a difficult. I'm wanting to log into https://ssl.rapidshare.com/ (which appears to be using Forms authentication). I've found the following WebClient code that is cookie aware:
public class CookieAwareWebClient:WebClient {
private CookieContainer m_container=new CookieContainer();
protected override WebRequest GetWebRequest(Uri address) {
WebRequest request=base.GetWebRequest(address);
if(request is HttpWebRequest) {
(request as HttpWebRequest).CookieContainer=m_container;
}
return request;
}
}
However, I'm afraid my code doesn't appear to be co-operating:
gWebClient=new CookieAwareWebClient();
if(gGroupEntry.GetStringProperty(CGroupEntry.EStringProperties.DownloadURL).Contains("rapidshare.com"))
gWebClient.Credentials=new System.Net.NetworkCredential(CSaverLoader.gUsername, CSaverLoader.gPassword, "https://ssl.rapidshare.com/");
gWebClient.DownloadFileCompleted+=new AsyncCompletedEventHandler(gWebClient_DownloadFileCompleted);
gWebClient.DownloadProgressChanged+=new DownloadProgressChangedEventHandler(gWebClient_DownloadProgressChanged);
gWebClient.DownloadFileAsync(new Uri(gGroupEntry.GetStringProperty(CGroupEntry.EStringProperties.DownloadURL)), gDownloadDirectory+"/"+gGroupEntry.GetStringProperty(CGroupEntry.EStringProperties.FileName));
Why could this be?