Aracılığıyla paylaş


WebClient.BaseAddress Özellik

Tanım

tarafından WebClientyapılan istekler için temel URI'yi alır veya ayarlar.

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

Özellik Değeri

Veya String hiçbir temel adres belirtilmemişse, bir WebClientEmpty tarafından yapılan istekler için temel URI'yi içeren.

Özel durumlar

BaseAddress geçersiz bir URI'ye ayarlanmış. İç özel durum, hatayı bulmanıza yardımcı olacak bilgiler içerebilir.

Örnekler

Aşağıdaki kod örneği bir İnternet sunucusundan verileri indirir ve konsolda görüntüler. Sunucunun adresinin (örneğin http://www.contoso.com) içinde hostUri olduğunu ve kaynağın yolunun (/default.htm gibi) içinde uriSuffixolduğunu varsayar.

// 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."))

Açıklamalar

özelliği, BaseAddress göreli bir adresle birleştirilen bir temel URI içerir. Verileri karşıya yükleyen veya indiren bir yöntemi çağırdığınızda, WebClient nesnesi bu temel URI'yi yöntem çağrısında belirttiğiniz göreli adresle birleştirir. Mutlak bir URI belirtirseniz, WebClient özellik değerini kullanmaz BaseAddress .

Önceden ayarlanmış bir değeri kaldırmak için bu özelliği null veya boş bir dize ("") olarak ayarlayın.

Şunlara uygulanır