WebRequest.RequestUri Vlastnost

Definice

Při přepsání v odvozené třídě získá identifikátor URI internetového prostředku přidruženého k požadavku.

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

Hodnota vlastnosti

Uri

Představující Uri prostředek přidružený k požadavku.

Výjimky

Jakýkoli pokus o získání nebo nastavení vlastnosti, pokud vlastnost není přepsána v odvozené třídě.

Příklady

Následující příklad zkontroluje RequestUri vlastnost a určí původně požadovaný web.

// 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 ()

Poznámky

Při přepsání v odvozené třídě RequestUri obsahuje Uri vlastnost instanci, kterou Create metoda používá k vytvoření požadavku.

Poznámka

Třída WebRequest je abstract třída. Skutečné chování WebRequest instancí za běhu je určeno odvozenou třídou vrácenou metodou WebRequest.Create . Další informace o výchozích hodnotách a výjimkách najdete v dokumentaci pro odvozené třídy, například HttpWebRequest a FileWebRequest.

Poznámky pro implementátory

RequestUri musí obsahovat původní Uri instanci předanou Create(Uri) metodě . Pokud protokol dokáže požadavek přesměrovat na jiný identifikátor URI, musí potomek poskytnout vlastnost obsahující identifikátor URI, který požadavek skutečně vyhodí.

Platí pro

Viz také