WebClient.BaseAddress Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define o URI base para pedidos feitos 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 de Propriedade
A contendo String o URI base para pedidos feitos por um WebClient ou Empty se nenhum endereço base tiver sido especificado.
Exceções
BaseAddress está definido para um URI inválido. A exceção interna pode conter informações que o ajudarão a localizar o erro.
Exemplos
O seguinte exemplo de código descarrega dados de um servidor de Internet e exibe-os na consola. Assume 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."))
Observações
Atenção
WebRequest, HttpWebRequest, ServicePoint, e WebClient são obsoletos, e não deves usá-los para novos desenvolvimentos. Utilize HttpClient em substituição.
A BaseAddress propriedade contém um URI base que é combinado com um endereço relativo. Quando chama um método que carrega ou descarrega dados, o WebClient objeto combina este URI base com o endereço relativo que especifica na chamada ao método. Se especificar um URI absoluto, WebClient não use o valor da BaseAddress propriedade.
Para remover um valor previamente definido, defina esta propriedade como null ou uma cadeia vazia ("").