Freigeben über


HttpWebResponse.Server-Eigenschaft

Ruft den Namen des Servers ab, der die Antwort gesendet hat.

Namespace: System.Net
Assembly: System (in system.dll)

Syntax

'Declaration
Public ReadOnly Property Server As String
'Usage
Dim instance As HttpWebResponse
Dim value As String

value = instance.Server
public string Server { get; }
public:
property String^ Server {
    String^ get ();
}
/** @property */
public String get_Server ()
public function get Server () : String

Eigenschaftenwert

Eine Zeichenfolge mit dem Namen des Servers, der die Antwort gesendet hat.

Ausnahmen

Ausnahmetyp Bedingung

ObjectDisposedException

Die aktuelle Instanz wurde bereits verworfen.

Hinweise

Die Server-Eigenschaft enthält den Wert des mit der Antwort zurückgegebenen Server-Headers.

Beispiel

Im folgenden Beispiel wird mithilfe der Server-Eigenschaft der Name des Webservers auf der Konsole ausgegeben.

Try
      Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
      Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
      Dim method As String
      method = myHttpWebResponse.Method
      If [String].Compare(method, "GET") = 0 Then
          Console.WriteLine(ControlChars.NewLine + "The GET method was successfully invoked on the following Web Server : {0}", myHttpWebResponse.Server)
      End If
      ' Releases the resources of the response.
      myHttpWebResponse.Close()
  Catch e As WebException
      Console.WriteLine(ControlChars.NewLine + "Exception Raised. The following error occured : {0}", e.Status)
  Catch e As Exception
      Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
  End Try
    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->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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

HttpWebResponse-Klasse
HttpWebResponse-Member
System.Net-Namespace