WebClient.BaseAddress プロパティ

定義

WebClient で作成された要求のベース URI を取得または設定します。

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

プロパティ値

String で作成された要求のベース URI を格納する WebClient。ベース アドレスが指定されていない場合は Empty

例外

BaseAddress が無効な URI に設定されています。 この内部例外には、エラーの特定に役立つ情報が含まれている場合があります。

次のコード例では、インターネット サーバーからデータをダウンロードし、コンソールに表示します。 サーバーのアドレス (など http://www.contoso.com) が にあり hostUri 、リソースへのパス (/default.htm など) が 内 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."))

注釈

プロパティには BaseAddress 、相対アドレスと組み合わせたベース URI が含まれています。 データをアップロードまたはダウンロードするメソッドを呼び出すと、オブジェクトは WebClient 、このベース URI と、メソッド呼び出しで指定した相対アドレスを組み合わせます。 絶対 URI を指定した場合、 WebClient プロパティ値は BaseAddress 使用されません。

以前に設定した値を削除するには、このプロパティを または null 空の文字列 ("") に設定します。

適用対象