Hi,
I am trying to download a file from a remote webserver. I create the
following:
string username="remot eusername";
string password="remot epassword";
string URI="http://remote.target.s erver/getdocument.asp ?ID=sometest.pd f";
NetworkCredenti al nc = new NetworkCredenti al(username, password);
WebRequest req = WebRequest.Crea te(URI);
req.Credentials = nc;
WebResponse resp = req.GetResponse ();
using(FileStrea m fsb = new FileStream(file name, FileMode.Create New))
{
BinaryWriter bw = new BinaryWriter(fs b);
Byte[] read = new Byte[1024];
int bytes = resp.GetRespons eStream().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