次の方法で共有


WebClient.BaseAddress プロパティ

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

Public Property BaseAddress As String
[C#]
public string BaseAddress {get; set;}
[C++]
public: __property String* get_BaseAddress();public: __property void set_BaseAddress(String*);
[JScript]
public function get BaseAddress() : String;public function set BaseAddress(String);

プロパティ値

WebClient で作成された要求のベース URI。

例外

例外の種類 条件
ArgumentException BaseAddress が無効な URI に設定されています。

解説

BaseAddress プロパティには、アップロード メソッドまたはダウンロード メソッドを呼び出すときに指定する相対アドレスと結合されるベース URI が含まれています。

BaseAddress プロパティを設定する場合、次のメソッドを呼び出すときに指定する URI は、相対 URI にする必要があります。

使用例

[Visual Basic, C#, C++] インターネット サーバーからデータをダウンロードし、それをコンソールに表示する例を次に示します。サーバーのアドレス (https://www.contoso.com など) が hostUri にあり、リソースへのパス (/default.htm など) が uriSuffix にあることを前提にしています。

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

[C#] 
// 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.");

[C++] 
// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient->BaseAddress = hostUri;
Console::WriteLine(S"Downloading from {0}/ {1}", hostUri, uriSuffix);
Console::WriteLine(S"\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(S"Download of {0}{1} was successful.", myWebClient->BaseAddress, uriSuffix);

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

WebClient クラス | WebClient メンバ | System.Net 名前空間