WebRequest.RequestUri プロパティ

定義

派生クラスでオーバーライドされると、要求に関連付けられたインターネット リソースの URI を取得します。

public:
 abstract property Uri ^ RequestUri { Uri ^ get(); };
public:
 virtual property Uri ^ RequestUri { Uri ^ get(); };
public abstract Uri RequestUri { get; }
public virtual Uri RequestUri { get; }
member this.RequestUri : Uri
Public MustOverride ReadOnly Property RequestUri As Uri
Public Overridable ReadOnly Property RequestUri As Uri

プロパティ値

Uri

Uri要求に関連付けられているリソースを表す 。

例外

プロパティが派生クラスでオーバーライドされていないのに、そのプロパティの取得または設定が試行されました。

次の例では、 プロパティを RequestUri 調べて、最初に要求されたサイトを確認します。

// Create a new WebRequest object to the mentioned URL.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );
Console::WriteLine( "\nThe Uri requested is {0}", myWebRequest->RequestUri);
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();
      // Get the stream containing content returned by the server.
Stream^ streamResponse = myWebResponse->GetResponseStream();
      Console::WriteLine("\nThe Uri that responded to the request is '{0}'",myWebResponse->ResponseUri);
StreamReader^ reader = gcnew StreamReader(streamResponse);
      // Read the content.
String^ responseFromServer = reader->ReadToEnd();
// Display the content.
Console::WriteLine("\nThe HTML Contents received:");
Console::WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader->Close();
streamResponse->Close();
myWebResponse->Close();
      // Create a new WebRequest Object to the mentioned URL.
      WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");
      Console.WriteLine("\nThe Uri that was requested is {0}",myWebRequest.RequestUri);
      // Assign the response object of 'WebRequest' to a 'WebResponse' variable.
      WebResponse myWebResponse=myWebRequest.GetResponse();
      // Get the stream containing content returned by the server.
      Stream streamResponse=myWebResponse.GetResponseStream();
      Console.WriteLine("\nThe Uri that responded to the WebRequest is '{0}'",myWebResponse.ResponseUri);
StreamReader reader = new StreamReader (streamResponse);
      // Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine("\nThe HTML Contents received:");
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
streamResponse.Close ();
myWebResponse.Close ();
' Create a new WebRequest Object to the mentioned URL.
Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")
Console.WriteLine(ControlChars.Cr + ControlChars.Lf +"The Uri that was requested is {0}", myWebRequest.RequestUri)
' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
      ' Get the stream containing content returned by the server.
Dim streamResponse As Stream = myWebResponse.GetResponseStream()
Console.WriteLine(ControlChars.Cr + ControlChars.Lf + "The Uri that responded to the request is {0}", myWebResponse.ResponseUri)
' Print the HTML contents of the page to the console. 
Dim reader As New StreamReader(streamResponse)
      ' Read the content.
      Dim responseFRomServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(ControlChars.Cr + ControlChars.Lf +"The HTML Contents received:")
Console.WriteLine (responseFromServer)
' Cleanup the streams and the response.
reader.Close ()
streamResponse.Close ()
myWebResponse.Close ()

注釈

子孫クラスでオーバーライドされると、 プロパティには、 RequestUri メソッドが要求の Uri 作成に使用する Create インスタンスが含まれます。

注意

クラスは WebRequest クラスです abstract 。 実行時のインスタンスの実際の WebRequest 動作は、 メソッドによって返される子孫クラスによって WebRequest.Create 決定されます。 既定値と例外の詳細については、 や などのHttpWebRequestFileWebRequest子孫クラスのドキュメントを参照してください。

注意 (実装者)

RequestUri には、 メソッドに渡された元 Uri のインスタンスが Create(Uri) 含まれている必要があります。 プロトコルが要求を別の URI にリダイレクトして要求を処理できる場合、子孫は、要求に実際にサービスを提供する URI を含むプロパティを提供する必要があります

適用対象

こちらもご覧ください