WebClient.DownloadData 메서드

정의

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

오버로드

DownloadData(String)

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

DownloadData(Uri)

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

DownloadData(String)

리소스를 지정된 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.")

설명

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

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

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

참고

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

적용 대상

DownloadData(Uri)

리소스를 지정된 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를 포함하지 않는 경우 요청된 데이터의 절대 URI address 를 형성하기 위해 결합된 BaseAddress 상대 URI여야 합니다. 속성이 QueryString 빈 문자열이 아니면 .에 address추가됩니다.

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

참고

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

적용 대상