1

I am trying to get pdf file data using webclient but it is throwing an exception of "The remote server returned an error: (404) Not Found."

Here are error details:

System.Net.WebException was caught

Message=The remote server returned an error: (404) Not Found. Source=System

StackTrace: at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadData(Uri address) at System.Net.WebClient.DownloadData(String address)

Error Status: System.Net.WebExceptionStatus.ProtocolError

Here is the code snippet am using to download data:

try{
    WebClient cl = new WebClient();
    byte[] data = cl.DownloadData(URL);
}
catch(exception ex){

}

Any idea??

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
User0000
  • 11
  • 3

1 Answers1

0

You should supply credentials. Similar to the following

try
{
     WebClient cl = new WebClient();
     cl.UseDefaultCredentials = true;
      byte[] data = cl.DownloadData(URL);
}
catch (exception ex)
{
}
Jens Meinecke
  • 2,904
  • 17
  • 20