WebClient.UploadData 메서드

정의

지정된 URI를 사용하여 리소스에 데이터 버퍼를 업로드합니다.

오버로드

UploadData(String, Byte[])

URI로 식별되는 리소스에 데이터 버퍼를 업로드합니다.

UploadData(Uri, Byte[])

URI로 식별되는 리소스에 데이터 버퍼를 업로드합니다.

UploadData(String, String, Byte[])

지정된 메서드를 사용하여 지정된 리소스에 데이터 버퍼를 업로드합니다.

UploadData(Uri, String, Byte[])

지정된 메서드를 사용하여 지정된 리소스에 데이터 버퍼를 업로드합니다.

UploadData(String, Byte[])

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

URI로 식별되는 리소스에 데이터 버퍼를 업로드합니다.

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

매개 변수

address
String

데이터를 받을 리소스의 URI입니다.

data
Byte[]

리소스에 보낼 데이터 버퍼입니다.

반환

Byte[]

리소스의 응답 본문이 포함된 Byte 배열입니다.

예외

address 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

datanull입니다.

또는

데이터를 보내는 동안 오류가 발생한 경우

또는

리소스를 호스팅하는 서버에서 응답이 없는 경우

예제

다음 코드 예제에서는 콘솔에서 입력한 문자열을 배열로 Byte 변환하고 를 사용하여 UploadData배열을 지정된 서버에 게시합니다. 서버의 모든 응답이 콘솔에 표시됩니다.

Console::Write( "\nPlease enter the URI to post data to: " );
String^ uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
// Apply ASCII Encoding to obtain the String* as a Byte array.
array<Byte>^ postArray = Encoding::ASCII->GetBytes( postData );
Console::WriteLine( "Uploading to {0} ...", uriString );
myWebClient->Headers->Add( "Content-Type", "application/x-www-form-urlencoded" );

//UploadData implicitly sets HTTP POST as the request method.
array<Byte>^responseArray = myWebClient->UploadData( uriString, postArray );

// Decode and display the response.
Console::WriteLine( "\nResponse received was: {0}", Encoding::ASCII->GetString( responseArray ) );
    Console.Write("\nPlease enter the URI to post data to : ");
    string uriString = Console.ReadLine();
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
    string postData = Console.ReadLine();
    // Apply ASCII Encoding to obtain the string as a byte array.
    byte[] postArray = Encoding.ASCII.GetBytes(postData);
    Console.WriteLine("Uploading to {0} ...",  uriString);							
 myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");

    //UploadData implicitly sets HTTP POST as the request method.
    byte[] responseArray = myWebClient.UploadData(uriString,postArray);

    // Decode and display the response.
    Console.WriteLine("\nResponse received was :{0}", Encoding.ASCII.GetString(responseArray));
Console.Write(ControlChars.Cr + "Please enter the URI to post data to : ")
Dim uriString As String = Console.ReadLine()

' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
' Apply ASCII Encoding to obtain the string as a byte array.
Dim postArray As Byte() = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

' UploadData implicitly sets HTTP POST as the request method.
Dim responseArray As Byte() = myWebClient.UploadData(uriString, postArray)

' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}", Encoding.ASCII.GetString(responseArray))

설명

메서드는 UploadData 리소스에 데이터 버퍼를 보냅니다.

이 메서드는 STOR 명령을 사용하여 FTP 리소스를 업로드합니다. HTTP 리소스의 경우 POST 메서드가 사용됩니다. 기본 요청이 서버에서 이해되지 않는 경우 기본 프로토콜 클래스는 발생하는 사항을 결정합니다. 일반적으로 WebException 는 오류를 나타내기 위해 속성이 설정된 상태에서 Status throw됩니다.

메서드는 UploadData 인코딩하지 않고 의 data 콘텐츠를 서버로 보냅니다. 이 메서드는 데이터를 업로드하는 동안 차단합니다. 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 UploadDataAsync 하나를 사용합니다.

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

참고

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

적용 대상

UploadData(Uri, Byte[])

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

URI로 식별되는 리소스에 데이터 버퍼를 업로드합니다.

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

매개 변수

address
Uri

데이터를 받을 리소스의 URI입니다.

data
Byte[]

리소스에 보낼 데이터 버퍼입니다.

반환

Byte[]

리소스의 응답 본문이 포함된 Byte 배열입니다.

예외

address 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

datanull입니다.

또는

데이터를 보내는 동안 오류가 발생한 경우

또는

리소스를 호스팅하는 서버에서 응답이 없는 경우

설명

메서드는 UploadData 리소스에 데이터 버퍼를 보냅니다.

이 메서드는 STOR 명령을 사용하여 FTP 리소스를 업로드합니다. HTTP 리소스의 경우 POST 메서드가 사용됩니다. 기본 요청이 서버에서 이해되지 않는 경우 기본 프로토콜 클래스는 발생하는 사항을 결정합니다. 일반적으로 WebException 는 오류를 나타내기 위해 속성이 설정된 상태에서 Status throw됩니다.

메서드는 UploadData 인코딩하지 않고 의 data 콘텐츠를 서버로 보냅니다. 이 메서드는 데이터를 업로드하는 동안 차단합니다. 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 UploadDataAsync 하나를 사용합니다.

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

참고

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

적용 대상

UploadData(String, String, Byte[])

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

지정된 메서드를 사용하여 지정된 리소스에 데이터 버퍼를 업로드합니다.

public:
 cli::array <System::Byte> ^ UploadData(System::String ^ address, System::String ^ method, cli::array <System::Byte> ^ data);
public byte[] UploadData (string address, string? method, byte[] data);
public byte[] UploadData (string address, string method, byte[] data);
member this.UploadData : string * string * byte[] -> byte[]
Public Function UploadData (address As String, method As String, data As Byte()) As Byte()

매개 변수

address
String

데이터를 받을 리소스의 URI입니다.

method
String

리소스에 데이터를 보내는 데 사용되는 HTTP 메서드입니다. null인 경우 http의 기본값은 POST이고 ftp의 기본값은 STOR입니다.

data
Byte[]

리소스에 보낼 데이터 버퍼입니다.

반환

Byte[]

리소스의 응답 본문이 포함된 Byte 배열입니다.

예외

address 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

datanull입니다.

또는

데이터를 업로드하는 동안 오류가 발생한 경우

또는

리소스를 호스팅하는 서버에서 응답이 없는 경우

예제

다음 코드 예제에서는 콘솔에서 입력한 문자열을 바이트 배열로 변환하고 를 사용하여 UploadData배열을 지정된 서버에 게시합니다. 서버의 모든 응답이 콘솔에 표시됩니다.

String^ uriString;
Console::Write( "\nPlease enter the URI to post data to {for example, http://www.contoso.com}: " );
uriString = Console::ReadLine();

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
myWebClient->Headers->Add( "Content-Type", "application/x-www-form-urlencoded" );

// Displays the headers in the request
Console::Write( "Resulting Request Headers: ");
Console::WriteLine(myWebClient->Headers);

// Apply ASCII Encoding to obtain the String^ as a Byte array.
array<Byte>^ byteArray = Encoding::ASCII->GetBytes( postData );
Console::WriteLine( "Uploading to {0} ...", uriString );
// Upload the input String* using the HTTP 1.0 POST method.
array<Byte>^responseArray = myWebClient->UploadData( uriString, "POST", byteArray );
// Decode and display the response.
Console::WriteLine( "\nResponse received was {0}",
   Encoding::ASCII->GetString( responseArray ) );
   string uriString;
       Console.Write("\nPlease enter the URI to post data to {for example, http://www.contoso.com} : ");
       uriString = Console.ReadLine();

       // Create a new WebClient instance.
       WebClient myWebClient = new WebClient();
       Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
       string postData = Console.ReadLine();
       myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");

 // Display the headers in the request
       Console.Write("Resulting Request Headers: ");
       Console.WriteLine(myWebClient.Headers.ToString());
       
       // Apply ASCII Encoding to obtain the string as a byte array.

       byte[] byteArray = Encoding.ASCII.GetBytes(postData);
       Console.WriteLine("Uploading to {0} ...",  uriString);						
       // Upload the input string using the HTTP 1.0 POST method.
       byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
       
       // Decode and display the response.
       Console.WriteLine("\nResponse received was {0}",
       Encoding.ASCII.GetString(responseArray));
                 
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for example, http://www.contoso.com} : ")
uriString = Console.ReadLine()

' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

' Display the headers in the request
Console.Write("Resulting Request Headers: ")
Console.Writeline(myWebClient.Headers.ToString())

' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte() = myWebClient.UploadData(uriString, "POST", byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}", Encoding.ASCII.GetString(responseArray))

설명

메서드는 UploadData 매개 변수에 지정된 HTTP 메서드를 사용하여 리소스에 데이터 버퍼를 method 보내고 서버의 모든 응답을 반환합니다. 이 메서드는 데이터를 업로드하는 동안 차단합니다. 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 UploadDataAsync 하나를 사용합니다.

메서드는 UploadData 인코딩하지 않고 의 data 콘텐츠를 서버로 보냅니다.

매개 변수가 서버에서 method 인식할 수 없는 동사를 지정하는 경우 기본 프로토콜 클래스는 발생 원인을 결정합니다. 일반적으로 WebException 는 오류를 나타내기 위해 속성이 설정된 상태에서 Status throw됩니다.

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

참고

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

적용 대상

UploadData(Uri, String, Byte[])

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

지정된 메서드를 사용하여 지정된 리소스에 데이터 버퍼를 업로드합니다.

public:
 cli::array <System::Byte> ^ UploadData(Uri ^ address, System::String ^ method, cli::array <System::Byte> ^ data);
public byte[] UploadData (Uri address, string? method, byte[] data);
public byte[] UploadData (Uri address, string method, byte[] data);
member this.UploadData : Uri * string * byte[] -> byte[]
Public Function UploadData (address As Uri, method As String, data As Byte()) As Byte()

매개 변수

address
Uri

데이터를 받을 리소스의 URI입니다.

method
String

리소스에 데이터를 보내는 데 사용되는 HTTP 메서드입니다. null인 경우 http의 기본값은 POST이고 ftp의 기본값은 STOR입니다.

data
Byte[]

리소스에 보낼 데이터 버퍼입니다.

반환

Byte[]

리소스의 응답 본문이 포함된 Byte 배열입니다.

예외

address 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

datanull입니다.

또는

데이터를 업로드하는 동안 오류가 발생한 경우

또는

리소스를 호스팅하는 서버에서 응답이 없는 경우

설명

메서드는 UploadData 매개 변수에 지정된 HTTP 메서드를 사용하여 리소스에 데이터 버퍼를 method 보내고 서버의 모든 응답을 반환합니다. 이 메서드는 데이터를 업로드하는 동안 차단합니다. 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 UploadDataAsync 하나를 사용합니다.

메서드는 UploadData 인코딩하지 않고 의 data 콘텐츠를 서버로 보냅니다.

매개 변수가 서버에서 method 인식할 수 없는 동사를 지정하는 경우 기본 프로토콜 클래스는 발생 원인을 결정합니다. 일반적으로 WebException 는 오류를 나타내기 위해 속성이 설정된 상태에서 Status throw됩니다.

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

참고

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

적용 대상