WebRequest.RequestUri Eigenschaft

Definition

Ruft beim Überschreiben in einer Nachfolgerklasse den mit der Anforderung verknüpften URI der Internetressource ab.

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

Eigenschaftswert

Uri

Ein Uri , der die der Anforderung zugeordnete Ressource darstellt.

Ausnahmen

Es wurde versucht, die Eigenschaft abzurufen oder festzulegen, obwohl die Eigenschaft in einer Nachfolgerklasse nicht überschrieben wurde.

Beispiele

Im folgenden Beispiel wird die RequestUri Eigenschaft überprüft, um die ursprünglich angeforderte Website zu ermitteln.

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

Hinweise

Beim Überschreiben in einer untergeordneten Klasse enthält die RequestUri -Eigenschaft den Uri instance, den diese Create Methode zum Erstellen der Anforderung verwendet.

Hinweis

Die WebRequest -Klasse ist eine abstract Klasse. Das tatsächliche Verhalten von WebRequest Instanzen zur Laufzeit wird durch die von der WebRequest.Create -Methode zurückgegebene untergeordnete Klasse bestimmt. Weitere Informationen zu Standardwerten und Ausnahmen finden Sie in der Dokumentation für die untergeordneten Klassen, z. B HttpWebRequest . und FileWebRequest.

Hinweise für Ausführende

RequestUrimuss den ursprünglichen Uri instance enthalten, der an die Create(Uri) -Methode übergeben wurde. Wenn das Protokoll in der Lage ist, die Anforderung an einen anderen URI umzuleiten, um die Anforderung zu verarbeiten, muss der Nachfolger eine Eigenschaft bereitstellen, die den URI enthält, der die Anforderung tatsächlich bedient.

Gilt für:

Weitere Informationen