HttpWebResponse.Server プロパティ
応答を送信したサーバーの名前を取得します。
Public ReadOnly Property Server As String
[C#]
public string Server {get;}
[C++]
public: __property String* get_Server();
[JScript]
public function get Server() : String;
プロパティ値
応答を送信したサーバーの名前を格納する文字列。
例外
例外の種類 | 条件 |
---|---|
ObjectDisposedException | 現在のインスタンスは破棄されています。 |
解説
Server プロパティは、応答で返される Server ヘッダーの値を格納します。
使用例
[Visual Basic, C#, C++] Server プロパティを使用して、Web サーバーの名前をコンソールに表示する例を次に示します。
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
[C#]
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);
}
}
[C++]
try {
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(url));
HttpWebResponse* myHttpWebResponse =
dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
String* method ;
method = myHttpWebResponse->Method;
if (String::Compare(method, S"GET") == 0)
Console::WriteLine(S"\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(S"\nWebException raised. The following error occured : {0}",
__box(e->Status));
} catch (Exception* e) {
Console::WriteLine(S"\nThe following Exception was raised : {0}",
e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard