WebClient.DownloadData メソッド

定義

指定した URI から Byte 配列としてリソースをダウンロードします。

オーバーロード

DownloadData(String)

指定した URI から Byte 配列としてリソースをダウンロードします。

DownloadData(Uri)

指定した URI から Byte 配列としてリソースをダウンロードします。

DownloadData(String)

ソース:
WebClient.cs
ソース:
WebClient.cs
ソース:
WebClient.cs

指定した URI から Byte 配列としてリソースをダウンロードします。

public:
 cli::array <System::Byte> ^ DownloadData(System::String ^ address);
public byte[] DownloadData (string address);
member this.DownloadData : string -> byte[]
Public Function DownloadData (address As String) As Byte()

パラメーター

address
String

データのダウンロード元の URI。

戻り値

Byte[]

ダウンロードされたリソースを格納している Byte 配列。

例外

address パラメーターが null です。

BaseAddress および address を組み合わせて形成された URI が無効です。

- または -

データのダウンロード中にエラーが発生しました。

このメソッドは、複数のスレッドで同時に呼び出されています。

次のコード例では、サーバーからデータを要求し、返されたデータを表示します。 には、 remoteUri 要求されたデータの有効な URI が含まれていることを前提としています。

Console::Write( "\nPlease enter a URI (e.g. http://www.contoso.com): " );
String^ remoteUri = Console::ReadLine();

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Download home page data.
Console::WriteLine( "Downloading {0}", remoteUri );
// Download the Web resource and save it into a data buffer.
array<Byte>^ myDataBuffer = myWebClient->DownloadData( remoteUri );

// Display the downloaded data.
String^ download = Encoding::ASCII->GetString( myDataBuffer );
Console::WriteLine( download );

Console::WriteLine( "Download successful." );
Console.Write("\nPlease enter a URI (for example, http://www.contoso.com): ");
string remoteUri = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);                        
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDataBuffer);
Console.WriteLine(download);
                    
Console.WriteLine("Download successful.");

Console.Write(ControlChars.Cr + "Please enter a Url(for example, http://www.msn.com): ")
Dim remoteUrl As String = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))
' DownloadData() method takes a 'uriRemote.ToString()' and downloads the Web resource and saves it into a data buffer.
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)

' Display the downloaded data.
Dim download As String = Encoding.ASCII.GetString(myDataBuffer)
Console.WriteLine(download)

Console.WriteLine("Download successful.")

注釈

メソッドは DownloadData 、 パラメーターで指定された URI を使用してリソースを address ダウンロードします。 このメソッドは、リソースのダウンロード中にブロックします。 リソースをダウンロードし、サーバーの応答を待機しながら実行を続けるには、いずれかのメソッドを DownloadDataAsync 使用します。

プロパティが BaseAddress 空の文字列 ("") address ではなく、絶対 URI を含まない場合は、 address と組み合わせて BaseAddress 、要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが空の QueryString 文字列でない場合は、 に address追加されます。

このメソッドは、RETR コマンドを使用して FTP リソースをダウンロードします。 HTTP リソースの場合は、GET メソッドが使用されます。

Note

このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「.NET Frameworkのネットワーク トレース」を参照してください。

適用対象

DownloadData(Uri)

ソース:
WebClient.cs
ソース:
WebClient.cs
ソース:
WebClient.cs

指定した URI から Byte 配列としてリソースをダウンロードします。

public:
 cli::array <System::Byte> ^ DownloadData(Uri ^ address);
public byte[] DownloadData (Uri address);
member this.DownloadData : Uri -> byte[]
Public Function DownloadData (address As Uri) As Byte()

パラメーター

address
Uri

Uri オブジェクトによって表される、データのダウンロード元の URI。

戻り値

Byte[]

ダウンロードされたリソースを格納している Byte 配列。

例外

address パラメーターが null です。

注釈

メソッドは DownloadData 、 パラメーターで指定された URI を使用してリソースを address ダウンロードします。 このメソッドは、リソースのダウンロード中にブロックします。 リソースをダウンロードし、サーバーの応答を待機しながら実行を続けるには、いずれかのメソッドを DownloadDataAsync 使用します。

プロパティが BaseAddress 空の文字列 ("") address ではなく、絶対 URI を含まない場合は、 address と組み合わせて BaseAddress 、要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが空の QueryString 文字列でない場合は、 に address追加されます。

このメソッドは、RETR コマンドを使用して FTP リソースをダウンロードします。 HTTP リソースの場合は、GET メソッドが使用されます。

Note

このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「.NET Frameworkのネットワーク トレース」を参照してください。

適用対象