المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : HttpWebRequest and HttpWebResponse



C# Programming
04-24-2009, 06:00 AM
Dear All,

I had the following code tested in my test environment, it works fine in my test environment

private bool CheckRcvFile********(string rcv********, ForeignSystem foreignSystem)
{

Uri uri1 = new Uri(rcv********);

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri1);

request.Credentials = foreignSystem.NetworkCredential;

request.Method = "HEAD";

HttpWebResponse response = null;

try
{

System.Console.WriteLine("test2");

if (request == null)

{

System.Console.WriteLine("Test2a");

}

else

{

System.Console.WriteLine("Test2b");

}

response = (HttpWebResponse)request.GetResponse();

System.Console.WriteLine("Test3");

return (response.StatusCode != HttpStatusCode.NotFound);

}

catch (WebException e)

{

response = (HttpWebResponse)e.Response;

if (response.StatusCode == HttpStatusCode.NotFound)

return false;

else

throw;

}

finally

{

if (response != null)

response.Close();

}

}

however when I put it into the real world, the "Test3" never gets executed, instead it returns me "Object reference not set to an instance of an object" as soon as the code goes to "response = (HttpWebResponse)request.GetResponse();"

Are there any settings that i need to aware to get these codes working in production environment?


regards


Andie