Aracılığıyla paylaş


WebClient.UploadValues Yöntem

Tanım

Belirtilen URI'ye sahip bir kaynağa bir ad/değer koleksiyonu yükler.

Aşırı Yüklemeler

UploadValues(String, NameValueCollection)

Belirtilen ad/değer koleksiyonunu belirtilen URI tarafından tanımlanan kaynağa yükler.

UploadValues(Uri, NameValueCollection)

Belirtilen ad/değer koleksiyonunu belirtilen URI tarafından tanımlanan kaynağa yükler.

UploadValues(String, String, NameValueCollection)

Belirtilen ad/değer koleksiyonunu belirtilen yöntemi kullanarak belirtilen URI tarafından tanımlanan kaynağa yükler.

UploadValues(Uri, String, NameValueCollection)

Belirtilen ad/değer koleksiyonunu belirtilen yöntemi kullanarak belirtilen URI tarafından tanımlanan kaynağa yükler.

UploadValues(String, NameValueCollection)

Kaynak:
WebClient.cs
Kaynak:
WebClient.cs
Kaynak:
WebClient.cs

Belirtilen ad/değer koleksiyonunu belirtilen URI tarafından tanımlanan kaynağa yükler.

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

Parametreler

address
String

Koleksiyonu alacak kaynağın URI'si.

data
NameValueCollection

NameValueCollection Kaynağa gönderilecek.

Döndürülenler

Byte[]

Byte Kaynaktan gelen yanıtın gövdesini içeren bir dizi.

Özel durumlar

address parametresidirnull.

-veya-

data parametresidirnull.

ve address birleştirilerek BaseAddressoluşturulan URI geçersiz.

-veya-

data, null değeridir.

-veya-

Kaynağı barındıran sunucudan yanıt alınmadı.

-veya-

Akışı açarken bir hata oluştu.

-veya-

Üst Content-type bilgi veya "application/x-www-form-urlencoded" değil null .

Örnekler

Aşağıdaki kod örneği kullanıcıdan (ad, yaş ve adres) bilgi toplar ve kullanarak değerleri sunucuya UploadValuespostalar. Sunucudan gelen tüm yanıtlar konsolda görüntülenir.

Console::Write( "\nPlease enter the URI to post data to: " );
String^ uriString = Console::ReadLine();

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection^ myNameValueCollection = gcnew NameValueCollection;

Console::WriteLine( "Please enter the following parameters to be posted to the URL" );
Console::Write( "Name: " );
String^ name = Console::ReadLine();

Console::Write( "Age: " );
String^ age = Console::ReadLine();

Console::Write( "Address: " );
String^ address = Console::ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add( "Name", name );
myNameValueCollection->Add( "Address", address );
myNameValueCollection->Add( "Age", age );

Console::WriteLine( "\nUploading to {0} ...", uriString );
// 'The Upload(String, NameValueCollection)' implicitly method sets HTTP POST as the request method.
array<Byte>^ responseArray = myWebClient->UploadValues( uriString, myNameValueCollection );

// Decode and display the response.
Console::WriteLine( "\nResponse received was :\n {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();

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();

Console.WriteLine("Please enter the following parameters to be posted to the URL");
Console.Write("Name:");
string name = Console.ReadLine();

Console.Write("Age:");
string age = Console.ReadLine();

Console.Write("Address:");
string address = Console.ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);            
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);

Console.WriteLine("\nUploading to {0} ...",  uriString);
// 'The Upload(String,NameValueCollection)' implicitly method sets HTTP POST as the request method.            
byte[] responseArray = myWebClient.UploadValues(uriString,myNameValueCollection);

// Decode and display the response.
Console.WriteLine("\nResponse received was :\n{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()
' Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection()
Console.WriteLine("Please enter the following parameters to be posted to the URL:")
Console.Write("Name:")
Dim name As String = Console.ReadLine()

Console.Write("Age:")
Dim age As String = Console.ReadLine()

Console.Write("Address:")
Dim address As String = Console.ReadLine()

' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)

Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...", uriString)
' The Upload(String,NameValueCollection)' method implicitly sets the HTTP POST as the request method.			
Dim responseArray As Byte() = myWebClient.UploadValues(uriString, myNameValueCollection)

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

Açıklamalar

UploadValues yöntemi bir NameValueCollection sunucuya gönderir. Bu yöntem verileri karşıya yüklerken engeller. Sunucunun yanıtını beklerken yürütmeye devam etmek için yöntemlerden birini UploadValuesAsync kullanın.

Temel alınan istek sunucu tarafından anlaşılmıyorsa, ne olduğunu temel protokol sınıfları belirler. Genellikle, hata belirtmek Status için özelliği ayarlanmış bir WebException oluşturulur.

content-type üst bilgisi ise nullUploadValues yöntemi bunu "application/x-www-form-urlencoded" olarak ayarlar.

BaseAddress Özellik boş bir dize ("") değilse ve address mutlak bir URI içermiyorsa, address istenen verilerin mutlak URI'sini oluşturmak için ile birleştirilen BaseAddress göreli bir URI olmalıdır. QueryString özelliği boş bir dize değilse, öğesine addresseklenir.

Bu yöntem bir FTP kaynağını karşıya yüklemek için STOR komutunu kullanır. BIR HTTP kaynağı için POST yöntemi kullanılır.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için bkz. .NET Framework'te Ağ İzleme.

Şunlara uygulanır

UploadValues(Uri, NameValueCollection)

Kaynak:
WebClient.cs
Kaynak:
WebClient.cs
Kaynak:
WebClient.cs

Belirtilen ad/değer koleksiyonunu belirtilen URI tarafından tanımlanan kaynağa yükler.

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

Parametreler

address
Uri

Koleksiyonu alacak kaynağın URI'si.

data
NameValueCollection

NameValueCollection Kaynağa gönderilecek.

Döndürülenler

Byte[]

Byte Kaynaktan gelen yanıtın gövdesini içeren bir dizi.

Özel durumlar

address parametresidirnull.

-veya-

data parametresidirnull.

ve address birleştirilerek BaseAddressoluşturulan URI geçersiz.

-veya-

data, null değeridir.

-veya-

Kaynağı barındıran sunucudan yanıt alınmadı.

-veya-

Akışı açarken bir hata oluştu.

-veya-

Üst Content-type bilgi veya "application/x-www-form-urlencoded" değil null .

Açıklamalar

UploadValues yöntemi bir NameValueCollection sunucuya gönderir. Bu yöntem verileri karşıya yüklerken engeller. Sunucunun yanıtını beklerken yürütmeye devam etmek için yöntemlerden birini UploadValuesAsync kullanın.

Temel alınan istek sunucu tarafından anlaşılmıyorsa, ne olduğunu temel protokol sınıfları belirler. Genellikle, hata belirtmek Status için özelliği ayarlanmış bir WebException oluşturulur.

content-type üst bilgisi ise nullUploadValues yöntemi bunu "application/x-www-form-urlencoded" olarak ayarlar.

BaseAddress Özellik boş bir dize ("") değilse ve address mutlak bir URI içermiyorsa, address istenen verilerin mutlak URI'sini oluşturmak için ile birleştirilen BaseAddress göreli bir URI olmalıdır. QueryString özelliği boş bir dize değilse, öğesine addresseklenir.

Bu yöntem bir FTP kaynağını karşıya yüklemek için STOR komutunu kullanır. BIR HTTP kaynağı için POST yöntemi kullanılır.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için bkz. .NET Framework'te Ağ İzleme.

Şunlara uygulanır

UploadValues(String, String, NameValueCollection)

Kaynak:
WebClient.cs
Kaynak:
WebClient.cs
Kaynak:
WebClient.cs

Belirtilen ad/değer koleksiyonunu belirtilen yöntemi kullanarak belirtilen URI tarafından tanımlanan kaynağa yükler.

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

Parametreler

address
String

Koleksiyonu alacak kaynağın URI'si.

method
String

Dosyayı kaynağa göndermek için kullanılan HTTP yöntemi. Null ise, varsayılan değer http için POST ve ftp için STOR'dır.

data
NameValueCollection

NameValueCollection Kaynağa gönderilecek.

Döndürülenler

Byte[]

Byte Kaynaktan gelen yanıtın gövdesini içeren bir dizi.

Özel durumlar

address parametresidirnull.

-veya-

data parametresidirnull.

ve address birleştirilerek BaseAddressoluşturulan URI geçersiz.

-veya-

data, null değeridir.

-veya-

Akışı açarken bir hata oluştu.

-veya-

Kaynağı barındıran sunucudan yanıt alınmadı.

-veya-

Content-type Üst bilgi değeri değildir null ve değildirapplication/x-www-form-urlencoded.

Örnekler

Aşağıdaki kod örneği kullanıcıdan (ad, yaş ve adres) bilgi toplar ve kullanarak değerleri sunucuya UploadValuespostalar. Sunucudan gelen tüm yanıtlar konsolda görüntülenir.

Console::Write( "\nPlease enter the URL to post data to: " );
String^ uriString = Console::ReadLine();

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection^ myNameValueCollection = gcnew NameValueCollection;

Console::WriteLine( "Please enter the following parameters to be posted to the URI" );
Console::Write( "Name: " );
String^ name = Console::ReadLine();

Console::Write( "Age: " );
String^ age = Console::ReadLine();

Console::Write( "Address: " );
String^ address = Console::ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add( "Name", name );
myNameValueCollection->Add( "Address", address );
myNameValueCollection->Add( "Age", age );
Console::WriteLine( "\nUploading to {0} ...", uriString );

// Upload the NameValueCollection.
array<Byte>^ responseArray = myWebClient->UploadValues( uriString, "POST", myNameValueCollection );

// Decode and display the response.
Console::WriteLine( "\nResponse received was :\n {0}", Encoding::ASCII->GetString( responseArray ) );
Console.Write("\nPlease enter the URL to post data to : ");
string uriString = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();

Console.WriteLine("Please enter the following parameters to be posted to the URI");
Console.Write("Name:");
string name = Console.ReadLine();

Console.Write("Age:");
string age = Console.ReadLine();

Console.Write("Address:");
string address = Console.ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);			
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);
Console.WriteLine("\nUploading to {0} ...",  uriString);

// Upload the NameValueCollection.
byte[] responseArray = myWebClient.UploadValues(uriString,"POST",myNameValueCollection);

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

' Create a new WebClient instance.
Dim myWebClient As New WebClient()

' Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection()

Console.WriteLine("Please enter the following parameters to be posted to the Url")
Console.Write("Name:")
Dim name As String = Console.ReadLine()

Console.Write("Age:")
Dim age As String = Console.ReadLine()

Console.Write("Address:")
Dim address As String = Console.ReadLine()

' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)

Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...", uriString)

' Upload the NameValueCollection.
Dim responseArray As Byte() = myWebClient.UploadValues(uriString, "POST", myNameValueCollection)

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

Açıklamalar

yöntemi, UploadValues parametresinde method belirtilen yöntemini kullanarak bir kaynağa gönderir NameValueCollection ve sunucudan herhangi bir yanıt döndürür. Bu yöntem verileri karşıya yüklerken engeller. Sunucunun yanıtını beklerken yürütmeye devam etmek için yöntemlerden birini UploadValuesAsync kullanın.

Content-type Üst bilgi ise nullUploadValues yöntemi bunu olarak application/x-www-form-urlencodedayarlar.

method parametresi sunucu tarafından anlaşılmayan bir fiil belirtiyorsa, ne olduğunu temel protokol sınıfları belirler. Genellikle, hata belirtmek Status için özelliği ayarlanmış bir WebException oluşturulur.

BaseAddress Özellik boş bir dize ("") değilse ve address mutlak bir URI içermiyorsa, address istenen verilerin mutlak URI'sini oluşturmak için ile birleştirilen BaseAddress göreli bir URI olmalıdır. QueryString özelliği boş bir dize değilse, öğesine addresseklenir.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için bkz. .NET Framework'te Ağ İzleme.

Şunlara uygulanır

UploadValues(Uri, String, NameValueCollection)

Kaynak:
WebClient.cs
Kaynak:
WebClient.cs
Kaynak:
WebClient.cs

Belirtilen ad/değer koleksiyonunu belirtilen yöntemi kullanarak belirtilen URI tarafından tanımlanan kaynağa yükler.

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

Parametreler

address
Uri

Koleksiyonu alacak kaynağın URI'si.

method
String

Dosyayı kaynağa göndermek için kullanılan HTTP yöntemi. Null ise, varsayılan değer http için POST ve ftp için STOR'dır.

data
NameValueCollection

NameValueCollection Kaynağa gönderilecek.

Döndürülenler

Byte[]

Byte Kaynaktan gelen yanıtın gövdesini içeren bir dizi.

Özel durumlar

address parametresidirnull.

-veya-

data parametresidirnull.

ve address birleştirilerek BaseAddressoluşturulan URI geçersiz.

-veya-

data, null değeridir.

-veya-

Akışı açarken bir hata oluştu.

-veya-

Kaynağı barındıran sunucudan yanıt alınmadı.

-veya-

Content-type Üst bilgi değeri değildir null ve değildirapplication/x-www-form-urlencoded.

Açıklamalar

yöntemi, UploadValues parametresinde method belirtilen yöntemini kullanarak bir kaynağa gönderir NameValueCollection ve sunucudan herhangi bir yanıt döndürür. Bu yöntem verileri karşıya yüklerken engeller. Sunucunun yanıtını beklerken yürütmeye devam etmek için yöntemlerden birini UploadValuesAsync kullanın.

Content-type Üst bilgi ise nullUploadValues yöntemi bunu olarak application/x-www-form-urlencodedayarlar.

method parametresi sunucu tarafından anlaşılmayan bir fiil belirtiyorsa, ne olduğunu temel protokol sınıfları belirler. Genellikle, hata belirtmek Status için özelliği ayarlanmış bir WebException oluşturulur.

BaseAddress Özellik boş bir dize ("") değilse ve address mutlak bir URI içermiyorsa, address istenen verilerin mutlak URI'sini oluşturmak için ile birleştirilen BaseAddress göreli bir URI olmalıdır. QueryString özelliği boş bir dize değilse, öğesine addresseklenir.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için bkz. .NET Framework'te Ağ İzleme.

Şunlara uygulanır