다음을 통해 공유


HttpWebResponse.ProtocolVersion 속성

정의

응답에 사용되는 HTTP 프로토콜의 버전을 가져옵니다.

public:
 property Version ^ ProtocolVersion { Version ^ get(); };
public Version ProtocolVersion { get; }
member this.ProtocolVersion : Version
Public ReadOnly Property ProtocolVersion As Version

속성 값

응답의 HTTP 프로토콜 버전을 포함하는 Version입니다.

예외

현재 인스턴스가 삭제된 경우

예제

이 예제에서는 에 HttpWebRequest 대한 및 쿼리를 HttpWebResponse만듭니다. 그런 다음 이 예제에서는 서버가 동일한 버전으로 응답하는지 확인합니다.

Uri^ ourUri = gcnew Uri( url );
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( ourUri ) );
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
// Ensures that only Http/1.0 responses are accepted.
if ( myHttpWebResponse->ProtocolVersion != HttpVersion::Version10 )
{
   Console::WriteLine( "\nThe server responded with a version other than Http/1.0" );
}
else if ( myHttpWebResponse->StatusCode == HttpStatusCode::OK )
{
   Console::WriteLine( "\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 " );
}
// Releases the resources of the response.
myHttpWebResponse->Close();
Uri ourUri = new Uri(url);
    // Creates an HttpWebRequest for the specified URL.
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri);
    myHttpWebRequest.ProtocolVersion = HttpVersion.Version10;
    // Sends the HttpWebRequest and waits for the response.
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
    // Ensures that only Http/1.0 responses are accepted.
    if(myHttpWebResponse.ProtocolVersion != HttpVersion.Version10)
        Console.WriteLine("\nThe server responded with a version other than Http/1.0");
    else
    if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
        Console.WriteLine("\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
    // Releases the resources of the response.
    myHttpWebResponse.Close();
Dim ourUri As New Uri(url)
' Creates an HttpWebRequest with the specified URL. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(ourUri), HttpWebRequest)
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10
' Sends the request and waits for the response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'The ProtocolVersion property is used to ensure that only Http/1.0 responses are accepted. 
If myHttpWebResponse.ProtocolVersion Is HttpVersion.Version10 Then
    Console.WriteLine(ControlChars.NewLine + "The server responded with a version other than Http/1.0")
Else
    If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
        Console.WriteLine(ControlChars.NewLine + "Request sent using version HTTP/1.0. Successfully received response with version Http/1.0 ")
    End If
End If
' Releases the resources of the response.
myHttpWebResponse.Close()

설명

속성에는 ProtocolVersion 인터넷 리소스에서 보낸 응답의 HTTP 프로토콜 버전 번호가 포함됩니다.

적용 대상