Problem with Proxies and HttpRequests

  • Thread starter Thread starter Andrew Weir
  • Start date Start date
A

Andrew Weir

Hello there,

I'm having a bit of trouble writing a program that reads an XML file
located on a webserver. I've had a go myself to try and code it but I'm
getting a strange error.

HttpWebRequest myWebRequest =
(HttpWebRequest)WebRequest.Create("http://webServer.com/");
WebProxy myWebProxy = new WebProxy("10.0.0.2");
NetworkCredential myCred = new NetworkCredential("user", "pass",
"domain.local");
myWebRequest.Proxy = myWebProxy;
myWebRequest.Proxy.Credentials = myCred;
HttpWebResponse myWebResponse =
(HttpWebResponse)myWebRequest.GetResponse();

// outputs the status of the http response.
Console.WriteLine(myWebResponse.StatusDescription);

If myWebRequest =
(HttpWebRequest)WebRequest.Create("http://webServer.com/"), everything
is fine and the myWebResponse is OK.

If mywebRequest =
(HttpWebRequest)WebRequest.Create("http://webServer.com/myfile.xml"),
then I have to process through an exception where it says remote server
(404) File not found.

The file is there however.

Suggestions?

Regards,
Andrew
 
Back
Top