HttpWebResponse.Server Property
.NET Framework 2.0
Gets the name of the server that sent the response.
Namespace: System.Net
Assembly: System (in system.dll)
Assembly: System (in system.dll)
The following example uses the Server property to display the Web server's name to the console.
try
{
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
string method ;
method = myHttpWebResponse.Method;
if (String.Compare(method,"GET") == 0)
Console.WriteLine("\nThe 'GET' method was successfully invoked on the following Web Server : {0}",
myHttpWebResponse.Server);
// Releases the resources of the response.
myHttpWebResponse.Close();
}
catch(WebException e)
{
Console.WriteLine("\nWebException raised. The following error occured : {0}",e.Status);
}
catch(Exception e)
{
Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
}
}
try {
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
myHttpWebRequest.GetResponse();
String method;
method = myHttpWebResponse.get_Method();
if (String.Compare(method, "GET") == 0) {
Console.WriteLine("\nThe 'GET' method was successfully invoked "
+ "on the following Web Server : {0}",
myHttpWebResponse.get_Server());
}
// Releases the resources of the response.
myHttpWebResponse.Close();
}
catch (WebException e) {
Console.WriteLine("\nWebException raised. The following error "
+ "occured : {0}", e.get_Status());
}
catch (System.Exception e) {
Console.WriteLine("\nThe following Exception was raised : {0}",
e.get_Message());
}
} //GetPage
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.