I am using This code to download a file
private WebClient client;
client = new WebClient();
if (isBusy)
{
client.CancelAsync();
isBusy = false;
this.downloadButton.Text = "Download";
}
else
{
try {
Uri uri = new Uri(urlTextBox.Text);
this.downloadProgressBar.Value = 0;
client.Headers.Add("User-Agent: Other");
client.DownloadFileAsync(uri, "test.csv.zip");
this.downloadButton.Text = "Cancel";
isBusy = true;
}
catch (UriFormatException ex) {
MessageBox.Show(ex.Message);
}
}
But I am getting an error the error is
Download Not Complete: The remote server returned an error: (403) Forbidden.
I dont know why it is coming .
But when i use the uri for downloading in Free download Manager its working
I added this line
client.Headers.Add("User-Agent: Other");
but its still not working.
There would be great appreciation if someone could help me.
Thanks In Advance.
It sounds like the free download manager you’re using might be spoofing the referer headers whereas your implementation is not. The server might be restricting downloads of the file you are attempting to download to only be downloadable if the referer field is set to a specific value (i.e. a site on the server). Have you attempted:
It might be worth using Fiddler to see the difference between the request the download manager sends and yours and then amend yours until it works.
Edit:
I’ve tested the URL you provided and I’ve got it working locally by adding the following:
You need to provide an “Accept” header otherwise the server does not know what your client wants / will accept. Here is my full anonimized sample application (using Sleep() for simplicity):