WebClient.BaseAddress Vlastnost

Definice

Získá nebo nastaví základní identifikátor URI pro požadavky provedené pomocí 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

Hodnota vlastnosti

A String obsahující základní identifikátor URI pro požadavky prováděné adresou WebClient nebo Empty pokud nebyla zadána žádná základní adresa.

Výjimky

BaseAddress je nastavený na neplatný identifikátor URI. Vnitřní výjimka může obsahovat informace, které vám pomůžou chybu najít.

Příklady

Následující příklad kódu stáhne data z internetového serveru a zobrazí je v konzole. Předpokládá, že adresa serveru (například http://www.contoso.com) je v hostUri a že cesta k prostředku (například /default.htm) je v 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."))

Poznámky

Vlastnost BaseAddress obsahuje základní identifikátor URI, který je kombinován s relativní adresou. Při volání metody, která nahrává nebo stahuje data, WebClient objekt kombinuje tento základní identifikátor URI s relativní adresou, kterou zadáte ve volání metody. Pokud zadáte absolutní identifikátor URI, WebClient nepoužije BaseAddress hodnotu vlastnosti.

Pokud chcete odebrat dříve nastavenou hodnotu, nastavte tuto vlastnost na null nebo prázdný řetězec ("").

Platí pro