WebClient.BaseAddress Propriedade

Definição

Obtém ou define o URI de base para solicitações feitas por um 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

Valor da propriedade

Um String que contém o URI base para solicitações feitas por um WebClient ou Empty se nenhum endereço básico foi especificado.

Exceções

BaseAddress é definido com um URI inválido. A exceção interna pode conter informações que ajudarão você a localizar o erro.

Exemplos

O exemplo de código a seguir baixa dados de um servidor da Internet e os exibe no console. Ele pressupõe que o endereço do servidor (como http://www.contoso.com) está em hostUri e que o caminho para o recurso (como /default.htm) está em 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."))

Comentários

A BaseAddress propriedade contém um URI base que é combinado com um endereço relativo. Quando você chama um método que carrega ou baixa dados, o WebClient objeto combina esse URI base com o endereço relativo especificado na chamada de método. Se você especificar um URI absoluto, WebClient não usará o valor da BaseAddress propriedade.

Para remover um valor definido anteriormente, defina essa propriedade como null ou uma cadeia de caracteres vazia ("").

Aplica-se a