First I should clarify that my Proxy
is set. The address and any necessary credentials are already successfully used in a login process to a web service. When downloading over a proxy, it is occasionally successful (~25% of the time), but most of the time it only partially downloads and "completes" with e.Error
set (see below).
public static void DownloadMyFile(string file)
{
Url = "https://myWebService.com/file.ext";
using (var client = new WebClient())
{
client.Proxy = proxy; //proxy is set and used elsewhere prior to logging in
//I use this event to manipulate my file when finished
client.DownloadFileCompleted += client_DownloadCompleted;
client.DownloadFileAsync(new Uri(Url), file);
}
}
The event that I use later on:
public static void client_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
//e has an error here, no point in doing anything useful with the file
//Do other "stuff"
}
The inner exception text/stack trace is:
The decryption operation failed, see inner exception.
at System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)
at System.Net.WebClient.DownloadBitsReadCallbackState(DownloadBitsState state, IAsyncResult result).
Again, to clarify: this works perfectly fine 100% of the time when not using a proxy.
Edit: The 2nd level inner exception message is The specified data could not be decrypted
. There is no stack trace associated with it