Hi,
I am trying to download a file from a remote webserver. I create the
following:
string username="remoteusername";
string password="remotepassword";
string URI="http://remote.target.server/getdocument.asp?ID=sometest.pdf";
NetworkCredential nc = new NetworkCredential(username, password);
WebRequest req = WebRequest.Create(URI);
req.Credentials = nc;
WebResponse resp = req.GetResponse();
using(FileStream fsb = new FileStream(filename, FileMode.CreateNew))
{
BinaryWriter bw = new BinaryWriter(fsb);
Byte[] read = new Byte[1024];
int bytes = resp.GetResponseStream().Read(read, 0, 1024);
...
// Carry on and stream the bytes to a local file
If I set the URI to a file in a directory on my localhost webserver (and
change the username and password) this works a treat. When I try to download
the remote file, I get 403 - Access forbidden. Unfortunately if a just enter
the URI into IE, I can view the file on screen. So I know I have permission,
I know the file exists, and I know the code works coz it works for the local
file.
Can anyone tell me where I'm going wrong?
Thanks,
Martin