HttpWebResponse.Server 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取发送响应的服务器的名称。
public:
property System::String ^ Server { System::String ^ get(); };
public string Server { get; }
member this.Server : string
Public ReadOnly Property Server As String
属性值
一个字符串,包含发送响应的服务器的名称。
例外
已释放当前实例。
示例
以下示例使用 Server 属性向控制台显示 Web 服务器的名称。
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 occurred : {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 occurred : {0}",e.Status);
}
catch(Exception e)
{
Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
}
}
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 occurred : {0}", e.Status)
Catch e As Exception
Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
End Try
注解
属性 Server 包含随响应一起返回的服务器标头的值。