WebClient.DownloadData 메서드

정의

지정된 URI에서 리소스를 Byte 배열로 다운로드합니다.

오버로드

DownloadData(String)

지정된 URI에서 리소스를 Byte 배열로 다운로드합니다.

DownloadData(Uri)

지정된 URI에서 리소스를 Byte 배열로 다운로드합니다.

DownloadData(String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
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.

BaseAddressaddress 결합하여 형성된 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.")

설명

주의

WebRequest, HttpWebRequest, ServicePointWebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.

DownloadData 메서드는 address 매개 변수로 지정된 URI를 사용하여 리소스를 다운로드합니다. 이 메서드는 리소스를 다운로드하는 동안 차단합니다. 리소스를 다운로드하고 서버의 응답을 기다리는 동안 계속 실행하려면 DownloadDataAsync 방법 중 하나를 사용합니다.

BaseAddress 속성이 빈 문자열("")이 아니고 address 절대 URI를 포함하지 않는 경우 address 요청된 데이터의 절대 URI를 형성하기 위해 BaseAddress 결합된 상대 URI여야 합니다. QueryString 속성이 빈 문자열이 아니면 address추가됩니다.

이 메서드는 RETR 명령을 사용하여 FTP 리소스를 다운로드합니다. HTTP 리소스의 경우 GET 메서드가 사용됩니다.

메모

이 멤버는 애플리케이션에서 네트워크 추적을 사용하도록 설정할 때 추적 정보를 출력합니다. 자세한 내용은 .NET Framework네트워크 추적을 참조하세요.

적용 대상

DownloadData(Uri)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
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.

설명

주의

WebRequest, HttpWebRequest, ServicePointWebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.

DownloadData 메서드는 address 매개 변수로 지정된 URI를 사용하여 리소스를 다운로드합니다. 이 메서드는 리소스를 다운로드하는 동안 차단합니다. 리소스를 다운로드하고 서버의 응답을 기다리는 동안 계속 실행하려면 DownloadDataAsync 방법 중 하나를 사용합니다.

BaseAddress 속성이 빈 문자열("")이 아니고 address 절대 URI를 포함하지 않는 경우 address 요청된 데이터의 절대 URI를 형성하기 위해 BaseAddress 결합된 상대 URI여야 합니다. QueryString 속성이 빈 문자열이 아니면 address추가됩니다.

이 메서드는 RETR 명령을 사용하여 FTP 리소스를 다운로드합니다. HTTP 리소스의 경우 GET 메서드가 사용됩니다.

메모

이 멤버는 애플리케이션에서 네트워크 추적을 사용하도록 설정할 때 추적 정보를 출력합니다. 자세한 내용은 .NET Framework네트워크 추적을 참조하세요.

적용 대상