Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft den Basis-URI für Anforderungen eines WebClient ab oder legt diesen fest.
Namespace: System.Net
Assembly: System (in system.dll)
Syntax
'Declaration
Public Property BaseAddress As String
'Usage
Dim instance As WebClient
Dim value As String
value = instance.BaseAddress
instance.BaseAddress = value
public string BaseAddress { get; set; }
public:
property String^ BaseAddress {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_BaseAddress ()
/** @property */
public void set_BaseAddress (String value)
public function get BaseAddress () : String
public function set BaseAddress (value : String)
Eigenschaftenwert
Ein String, der den Basis-URI für Anforderungen von WebClient oder Empty enthält, wenn keine Basisadresse angegeben wurde.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
BaseAddress ist auf einen ungültigen URI festgelegt. Die innere Ausnahme enthält möglicherweise Informationen, die Sie bei der Fehlersuche unterstützen. |
Hinweise
Die BaseAddress-Eigenschaft enthält einen Basis-URI, der mit einer relativen Adresse kombiniert ist. Wenn Sie eine Methode aufrufen, die einen Upload oder Download von Daten ausführt, kombiniert das WebClient-Objekt diesen Basis-URI mit der im Methodenaufruf angegebenen relativen Adresse. Wenn Sie einen absoluten URI angeben, verwendet WebClient nicht den BaseAddress-Eigenschaftenwert.
Wenn Sie einen zuvor festgelegten Wert entfernen möchten, legen Sie diese Eigenschaft auf NULL (Nothing in Visual Basic) oder eine leere Zeichenfolge ("") fest.
Beispiel
Im folgenden Codebeispiel wird ein Download von Daten von einem Internetserver ausgeführt und diese Daten werden in der Konsole angezeigt. Voraussetzung ist, dass sich die Serveradresse (z. B. https://www.contoso.com) im hostUri und der Pfad zu der Ressource (z. B. /default.htm) sich im uriSuffix befindet.
' 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."))
// 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.
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.set_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.
ubyte myDatabuffer[] = myWebClient.DownloadData(uriSuffix);
// Display the downloaded data.
String download = Encoding.get_ASCII().GetString(myDatabuffer);
Console.WriteLine(download);
Console.WriteLine("Download of " + myWebClient.get_BaseAddress().
ToString() + uriSuffix + " was successful.");
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0