WebClient.BaseAddress Właściwość

Definicja

Pobiera lub ustawia podstawowy identyfikator URI dla żądań wysyłanych przez element 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

Wartość właściwości

Identyfikator String URI podstawowy dla żądań wysyłanych przez obiekt WebClient lub Empty , jeśli nie określono żadnego adresu podstawowego.

Wyjątki

BaseAddress jest ustawiona na nieprawidłowy identyfikator URI. Wyjątek wewnętrzny może zawierać informacje ułatwiające zlokalizowanie błędu.

Przykłady

Poniższy przykład kodu pobiera dane z serwera internetowego i wyświetla je w konsoli programu . Przyjęto założenie, że adres serwera (na http://www.contoso.comprzykład ) znajduje się i hostUri że ścieżka do zasobu (na przykład /default.htm) znajduje się w 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."))

Uwagi

Właściwość BaseAddress zawiera podstawowy identyfikator URI, który jest połączony z adresem względnym. Podczas wywoływania metody, która przekazuje lub pobiera dane, WebClient obiekt łączy ten podstawowy identyfikator URI z adresem względnym określonym w wywołaniu metody. Jeśli określisz bezwzględny identyfikator URI, WebClient nie używa BaseAddress wartości właściwości.

Aby usunąć wcześniej ustawioną wartość, ustaw tę właściwość na null lub pusty ciąg ("").

Dotyczy