WebClient.BaseAddress Eigenschaft

Definition

Ruft den Basis-URI für Anforderungen eines WebClient ab oder legt diesen fest.Gets or sets the base URI for requests made by a WebClient.

public:
 property System::String ^ BaseAddress { System::String ^ get(); void set(System::String ^ value); };
public string BaseAddress { get; set; }
member this.BaseAddress : string with get, set
Public Property BaseAddress As String

Eigenschaftswert

Ein String, der den Basis-URI für Anforderungen von WebClient oder Empty enthält, wenn keine Basisadresse angegeben wurde.A String containing the base URI for requests made by a WebClient or Empty if no base address has been specified.

Ausnahmen

BaseAddress ist auf einen ungültigen URI festgelegt.BaseAddress is set to an invalid URI. Die innere Ausnahme enthält möglicherweise Informationen, die Sie bei der Fehlersuche unterstützen.The inner exception may contain information that will help you locate the error.

Beispiele

Im folgenden Codebeispiel werden Daten von einem Internet Server heruntergeladen und in der-Konsole angezeigt.The following code example downloads data from an Internet server and displays it on the console. Es setzt voraus, dass die Adresse des Servers (z. B. http://www.contoso.com) befindet sich im hostUri und der Pfad zu der Ressource (z. B./Default.htm) ist uriSuffix.It assumes that the server's address (such as http://www.contoso.com) is in hostUri and that the path to the resource (such as /default.htm) is in uriSuffix.

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient->BaseAddress = hostUri;
Console::WriteLine( "Downloading from {0}/ {1}", hostUri, uriSuffix );
Console::WriteLine( "\nPress Enter key to continue" );
Console::ReadLine();

// Download the target Web Resource into a Byte array.
array<Byte>^ myDatabuffer = myWebClient->DownloadData( uriSuffix );

// Display the downloaded data.
String^ download = Encoding::ASCII->GetString( myDatabuffer );
Console::WriteLine( download );
Console::WriteLine( "Download of {0}{1} was successful.", myWebClient->BaseAddress, uriSuffix );
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient.BaseAddress = hostUri;
Console.WriteLine("Downloading from " + hostUri + "/" + uriSuffix);
Console.WriteLine("\nPress Enter key to continue");
Console.ReadLine();	

// Download the target Web Resource into a byte array.
byte[] myDatabuffer = myWebClient.DownloadData (uriSuffix);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDatabuffer);
Console.WriteLine(download);

Console.WriteLine("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful.");
    ' Create a new WebClient instance.
    Dim myWebClient As New WebClient()

    ' Set the BaseAddress of the Web resource in the WebClient.
    myWebClient.BaseAddress = hostUri
    Console.WriteLine(("Downloading from " + hostUri + "/" + uriSuffix))
    Console.WriteLine(ControlChars.Cr + "Press Enter key to continue")
    Console.ReadLine()

    ' Download the target Web resource into a byte array.
    Dim myDatabuffer As Byte() = myWebClient.DownloadData(uriSuffix)

    ' Display the downloaded data.
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Console.WriteLine(download)

    Console.WriteLine(("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful."))

Hinweise

Die BaseAddress-Eigenschaft enthält einen Basis-URI, der mit einer relativen Adresse kombiniert wird.The BaseAddress property contains a base URI that is combined with a relative address. Wenn Sie eine Methode aufzurufen, mit der Daten hochgeladen oder heruntergeladen werden, kombiniert das WebClient-Objekt diesen Basis-URI mit der relativen Adresse, die Sie im Methodenaufrufe angeben.When you call a method that uploads or downloads data, the WebClient object combines this base URI with the relative address you specify in the method call. Wenn Sie einen absoluten URI angeben, verwendet WebClient nicht den BaseAddress-Eigenschafts Wert.If you specify an absolute URI, WebClient does not use the BaseAddress property value.

Um einen zuvor festgelegten Wert zu entfernen, legen Sie diese Eigenschaft auf null oder eine leere Zeichenfolge ("") fest.To remove a previously set value, set this property to null or an empty string ("").

Gilt für: