WebClient.BaseAddress Eigenschaft

Definition

Ruft den Basis-URI für Anforderungen eines WebClient ab oder legt diesen fest.

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.

Ausnahmen

BaseAddress ist auf einen ungültigen URI festgelegt. Die innere Ausnahme enthält möglicherweise Informationen, die Sie bei der Fehlersuche unterstützen.

Beispiele

Im folgenden Codebeispiel werden Daten von einem Internetserver heruntergeladen und auf der Konsole angezeigt. Es wird davon ausgegangen, dass sich die Adresse des Servers (z http://www.contoso.com. B. ) in hostUri befindet und der Pfad zur Ressource (z. B. /default.htm) in uriSuffixist.

// 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. Wenn Sie eine Methode aufrufen, die Daten hoch- oder herunterlädt, kombiniert das WebClient Objekt diesen Basis-URI mit der relativen Adresse, die Sie im Methodenaufruf angeben. Wenn Sie einen absoluten URI angeben, WebClient wird der BaseAddress -Eigenschaftswert nicht verwendet.

Um einen zuvor festgelegten Wert zu entfernen, legen Sie diese Eigenschaft auf null oder eine leere Zeichenfolge ("") fest.

Gilt für: