WebClient.UploadValues Metodo

Definizione

Carica un insieme nome/valore su una risorsa con l'URI specificato.

Overload

UploadValues(String, NameValueCollection)

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato.

UploadValues(Uri, NameValueCollection)

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato.

UploadValues(String, String, NameValueCollection)

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato utilizzando il metodo specificato.

UploadValues(Uri, String, NameValueCollection)

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato utilizzando il metodo specificato.

UploadValues(String, NameValueCollection)

Origine:
WebClient.cs
Origine:
WebClient.cs
Origine:
WebClient.cs

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato.

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()

Parametri

address
String

L'URI della risorsa per ricevere l'insieme.

data
NameValueCollection

L'oggetto NameValueCollection da inviare alla risorsa.

Restituisce

Byte[]

Matrice Byte contenente il corpo della risposta dalla risorsa.

Eccezioni

Il valore del parametro address è null.

-oppure-

Il valore del parametro data è null.

L'URI composto dalla combinazione di BaseAddress e address non è valido.

-oppure-

data è null.

-oppure-

Nessuna risposta dal server che ospita la risorsa.

-oppure-

Si è verificato un errore durante l'apertura del flusso.

-oppure-

L'intestazione Content-type non è null o "application/x-www-form-urlencoded".

Esempio

L'esempio di codice seguente raccoglie informazioni dall'utente (nome, età e indirizzo) e inserisce i valori nel server usando UploadValues. Qualsiasi risposta dal server viene visualizzata nella console.

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))

Commenti

Il UploadValues metodo invia un oggetto NameValueCollection a un server. Questo metodo si blocca durante il caricamento dei dati. Per continuare l'esecuzione durante l'attesa della risposta del server, usare uno dei UploadValuesAsync metodi .

Se la richiesta sottostante non viene compresa dal server, le classi di protocollo sottostanti determinano cosa accade. In genere, viene generata un'eccezione WebException con la Status proprietà impostata per indicare l'errore.

Se l'intestazione Content-type è null, il UploadValues metodo lo imposta su "application/x-www-form-urlencoded".

Se la BaseAddress proprietà non è una stringa vuota ("") e address non contiene un URI assoluto, address deve essere un URI relativo combinato con BaseAddress per formare l'URI assoluto dei dati richiesti. Se la QueryString proprietà non è una stringa vuota, viene aggiunta a address.

Questo metodo usa il comando STOR per caricare una risorsa FTP. Per una risorsa HTTP, viene usato il metodo POST.

Nota

Questo membro genera informazioni di traccia quando viene abilitata la funzionalità di traccia di rete nell'applicazione in uso. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Si applica a

UploadValues(Uri, NameValueCollection)

Origine:
WebClient.cs
Origine:
WebClient.cs
Origine:
WebClient.cs

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato.

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()

Parametri

address
Uri

L'URI della risorsa per ricevere l'insieme.

data
NameValueCollection

L'oggetto NameValueCollection da inviare alla risorsa.

Restituisce

Byte[]

Matrice Byte contenente il corpo della risposta dalla risorsa.

Eccezioni

Il valore del parametro address è null.

-oppure-

Il valore del parametro data è null.

L'URI composto dalla combinazione di BaseAddress e address non è valido.

-oppure-

data è null.

-oppure-

Nessuna risposta dal server che ospita la risorsa.

-oppure-

Si è verificato un errore durante l'apertura del flusso.

-oppure-

L'intestazione Content-type non è null o "application/x-www-form-urlencoded".

Commenti

Il UploadValues metodo invia un oggetto NameValueCollection a un server. Questo metodo si blocca durante il caricamento dei dati. Per continuare l'esecuzione durante l'attesa della risposta del server, usare uno dei UploadValuesAsync metodi .

Se la richiesta sottostante non viene compresa dal server, le classi di protocollo sottostanti determinano cosa accade. In genere, viene generata un'eccezione WebException con la Status proprietà impostata per indicare l'errore.

Se l'intestazione Content-type è null, il UploadValues metodo lo imposta su "application/x-www-form-urlencoded".

Se la BaseAddress proprietà non è una stringa vuota ("") e address non contiene un URI assoluto, address deve essere un URI relativo combinato con BaseAddress per formare l'URI assoluto dei dati richiesti. Se la QueryString proprietà non è una stringa vuota, viene aggiunta a address.

Questo metodo usa il comando STOR per caricare una risorsa FTP. Per una risorsa HTTP, viene usato il metodo POST.

Nota

Questo membro genera informazioni di traccia quando viene abilitata la funzionalità di traccia di rete nell'applicazione in uso. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Si applica a

UploadValues(String, String, NameValueCollection)

Origine:
WebClient.cs
Origine:
WebClient.cs
Origine:
WebClient.cs

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato utilizzando il metodo specificato.

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()

Parametri

address
String

L'URI della risorsa per ricevere l'insieme.

method
String

Il metodo HTTP utilizzato per inviare il file alla risorsa. Se il valore è null, l'impostazione predefinita sarà POST per http e STOR per ftp.

data
NameValueCollection

L'oggetto NameValueCollection da inviare alla risorsa.

Restituisce

Byte[]

Matrice Byte contenente il corpo della risposta dalla risorsa.

Eccezioni

Il valore del parametro address è null.

-oppure-

Il valore del parametro data è null.

L'URI composto dalla combinazione di BaseAddress e address non è valido.

-oppure-

data è null.

-oppure-

Si è verificato un errore durante l'apertura del flusso.

-oppure-

Nessuna risposta dal server che ospita la risorsa.

-oppure-

Il valore dell'intestazione Content-type non è null e non è application/x-www-form-urlencoded.

Esempio

L'esempio di codice seguente raccoglie informazioni dall'utente (nome, età e indirizzo) e inserisce i valori nel server usando UploadValues. Qualsiasi risposta dal server viene visualizzata nella console.

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))

Commenti

Il UploadValues metodo invia un NameValueCollection oggetto a una risorsa utilizzando il metodo specificato nel method parametro e restituisce qualsiasi risposta dal server. Questo metodo si blocca durante il caricamento dei dati. Per continuare l'esecuzione durante l'attesa della risposta del server, usare uno dei UploadValuesAsync metodi .

Se l'intestazione Content-type è null, il UploadValues metodo lo imposta su application/x-www-form-urlencoded.

Se il method parametro specifica un verbo non compreso dal server, le classi di protocollo sottostanti determinano cosa accade. In genere, viene generata un'eccezione WebException con la Status proprietà impostata per indicare l'errore.

Se la BaseAddress proprietà non è una stringa vuota ("") e address non contiene un URI assoluto, address deve essere un URI relativo combinato con BaseAddress per formare l'URI assoluto dei dati richiesti. Se la QueryString proprietà non è una stringa vuota, viene aggiunta a address.

Nota

Questo membro genera informazioni di traccia quando viene abilitata la funzionalità di traccia di rete nell'applicazione in uso. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Si applica a

UploadValues(Uri, String, NameValueCollection)

Origine:
WebClient.cs
Origine:
WebClient.cs
Origine:
WebClient.cs

Carica l'insieme nome/valore specificato nella risorsa identificata dall'URI specificato utilizzando il metodo specificato.

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()

Parametri

address
Uri

L'URI della risorsa per ricevere l'insieme.

method
String

Il metodo HTTP utilizzato per inviare il file alla risorsa. Se il valore è null, l'impostazione predefinita sarà POST per http e STOR per ftp.

data
NameValueCollection

L'oggetto NameValueCollection da inviare alla risorsa.

Restituisce

Byte[]

Matrice Byte contenente il corpo della risposta dalla risorsa.

Eccezioni

Il valore del parametro address è null.

-oppure-

Il valore del parametro data è null.

L'URI composto dalla combinazione di BaseAddress e address non è valido.

-oppure-

data è null.

-oppure-

Si è verificato un errore durante l'apertura del flusso.

-oppure-

Nessuna risposta dal server che ospita la risorsa.

-oppure-

Il valore dell'intestazione Content-type non è null e non è application/x-www-form-urlencoded.

Commenti

Il UploadValues metodo invia a NameValueCollection una risorsa usando il metodo specificato nel method parametro e restituisce qualsiasi risposta dal server. Questo metodo blocca durante il caricamento dei dati. Per continuare l'esecuzione durante l'attesa della risposta del server, usare uno dei UploadValuesAsync metodi.

Se l'intestazione è , il Content-typeUploadValues metodo lo imposta su application/x-www-form-urlencoded.null

Se il method parametro specifica un verbo non compreso dal server, le classi di protocollo sottostanti determinano ciò che si verifica. In genere, viene generato un WebException oggetto con la proprietà impostata per indicare l'errore Status .

Se la BaseAddress proprietà non è una stringa vuota ("") e address non contiene un URI assoluto, address deve essere un URI relativo combinato con BaseAddress per formare l'URI assoluto dei dati richiesti. Se la QueryString proprietà non è una stringa vuota, viene aggiunta a address.

Nota

Questo membro genera informazioni di traccia quando viene abilitata la funzionalità di traccia di rete nell'applicazione in uso. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Si applica a