WebClient.BaseAddress Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
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 uriSuffix
olduğ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
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin