WebClient.UploadValues Método

Definición

Carga una colección de nombres y valores en un recurso con el URI especificado.

Sobrecargas

UploadValues(String, NameValueCollection)

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado.

UploadValues(Uri, NameValueCollection)

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado.

UploadValues(String, String, NameValueCollection)

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado, utilizando el método especificado.

UploadValues(Uri, String, NameValueCollection)

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado, utilizando el método especificado.

UploadValues(String, NameValueCollection)

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

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado.

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

Parámetros

address
String

URI del recurso que recibirá la colección.

data
NameValueCollection

La NameValueCollection que se enviará al recurso.

Devoluciones

Byte[]

Matriz Byte que contiene el cuerpo de la respuesta del recurso.

Excepciones

El parámetro address es null.

o bien

El parámetro data es null.

El identificador URI formado al combinar BaseAddress y address no es válido.

o bien

data es null.

o bien

No hubo respuesta del servidor que hospeda el recurso.

o bien

Se ha producido un error al abrir la secuencia.

o bien

El encabezado Content-type no es null o "application/x-www-form-urlencoded".

Ejemplos

En el ejemplo de código siguiente se recopila información del usuario (nombre, edad y dirección) y se escriben los valores en el servidor mediante UploadValues. Cualquier respuesta del servidor se muestra en la consola.

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

Comentarios

El UploadValues método envía un NameValueCollection objeto a un servidor. Este método se bloquea al cargar los datos. Para continuar ejecutándose mientras espera la respuesta del servidor, use uno de los UploadValuesAsync métodos .

Si el servidor no entiende la solicitud subyacente, las clases de protocolo subyacente determinan lo que ocurre. Normalmente, se produce una WebException excepción con la Status propiedad establecida para indicar el error.

Si el encabezado Content-type es null, el UploadValues método lo establece en "application/x-www-form-urlencoded".

Si la BaseAddress propiedad no es una cadena vacía ("") y address no contiene un URI absoluto, address debe ser un URI relativo combinado con BaseAddress para formar el URI absoluto de los datos solicitados. Si la QueryString propiedad no es una cadena vacía, se anexa a address.

Este método usa el comando STOR para cargar un recurso FTP. Para un recurso HTTP, se usa el método POST.

Nota

Este miembro genera información de seguimiento cuando se habilita el seguimiento de red en la aplicación. Para obtener más información, consulte Seguimiento de red en .NET Framework.

Se aplica a

UploadValues(Uri, NameValueCollection)

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

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado.

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

Parámetros

address
Uri

URI del recurso que recibirá la colección.

data
NameValueCollection

La NameValueCollection que se enviará al recurso.

Devoluciones

Byte[]

Matriz Byte que contiene el cuerpo de la respuesta del recurso.

Excepciones

El parámetro address es null.

o bien

El parámetro data es null.

El identificador URI formado al combinar BaseAddress y address no es válido.

o bien

data es null.

o bien

No hubo respuesta del servidor que hospeda el recurso.

o bien

Se ha producido un error al abrir la secuencia.

o bien

El encabezado Content-type no es null o "application/x-www-form-urlencoded".

Comentarios

El UploadValues método envía un NameValueCollection objeto a un servidor. Este método se bloquea al cargar los datos. Para continuar ejecutándose mientras espera la respuesta del servidor, use uno de los UploadValuesAsync métodos .

Si el servidor no entiende la solicitud subyacente, las clases de protocolo subyacente determinan lo que ocurre. Normalmente, se produce una WebException excepción con la Status propiedad establecida para indicar el error.

Si el encabezado Content-type es null, el UploadValues método lo establece en "application/x-www-form-urlencoded".

Si la BaseAddress propiedad no es una cadena vacía ("") y address no contiene un URI absoluto, address debe ser un URI relativo combinado con BaseAddress para formar el URI absoluto de los datos solicitados. Si la QueryString propiedad no es una cadena vacía, se anexa a address.

Este método usa el comando STOR para cargar un recurso FTP. Para un recurso HTTP, se usa el método POST.

Nota

Este miembro genera información de seguimiento cuando se habilita el seguimiento de red en la aplicación. Para obtener más información, consulte Seguimiento de red en .NET Framework.

Se aplica a

UploadValues(String, String, NameValueCollection)

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

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado, utilizando el método especificado.

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

Parámetros

address
String

URI del recurso que recibirá la colección.

method
String

Método HTTP que se utiliza para enviar el archivo al recurso. Si es null, el valor predeterminado es POST para http y STOR para ftp.

data
NameValueCollection

La NameValueCollection que se enviará al recurso.

Devoluciones

Byte[]

Matriz Byte que contiene el cuerpo de la respuesta del recurso.

Excepciones

El parámetro address es null.

o bien

El parámetro data es null.

El identificador URI formado al combinar BaseAddress y address no es válido.

o bien

data es null.

o bien

Se ha producido un error al abrir la secuencia.

o bien

No hubo respuesta del servidor que hospeda el recurso.

o bien

El valor del encabezado Content-type no es null ni application/x-www-form-urlencoded.

Ejemplos

En el ejemplo de código siguiente se recopila información del usuario (nombre, edad y dirección) y se escriben los valores en el servidor mediante UploadValues. Cualquier respuesta del servidor se muestra en la consola.

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

Comentarios

El UploadValues método envía un NameValueCollection objeto a un recurso mediante el método especificado en el method parámetro y devuelve cualquier respuesta del servidor. Este método se bloquea al cargar los datos. Para continuar ejecutándose mientras espera la respuesta del servidor, use uno de los UploadValuesAsync métodos .

Si el Content-type encabezado es null, el UploadValues método lo establece en application/x-www-form-urlencoded.

Si el method parámetro especifica un verbo que el servidor no entiende, las clases de protocolo subyacente determinan lo que ocurre. Normalmente, se produce una WebException excepción con la Status propiedad establecida para indicar el error.

Si la BaseAddress propiedad no es una cadena vacía ("") y address no contiene un URI absoluto, address debe ser un URI relativo combinado con BaseAddress para formar el URI absoluto de los datos solicitados. Si la QueryString propiedad no es una cadena vacía, se anexa a address.

Nota

Este miembro genera información de seguimiento cuando se habilita el seguimiento de red en la aplicación. Para obtener más información, vea Seguimiento de red en .NET Framework.

Se aplica a

UploadValues(Uri, String, NameValueCollection)

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

Carga la colección de nombres y valores especificada en el recurso identificado mediante el URI especificado, utilizando el método especificado.

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

Parámetros

address
Uri

URI del recurso que recibirá la colección.

method
String

Método HTTP que se utiliza para enviar el archivo al recurso. Si es null, el valor predeterminado es POST para http y STOR para ftp.

data
NameValueCollection

La NameValueCollection que se enviará al recurso.

Devoluciones

Byte[]

Matriz Byte que contiene el cuerpo de la respuesta del recurso.

Excepciones

El parámetro address es null.

o bien

El parámetro data es null.

El identificador URI formado al combinar BaseAddress y address no es válido.

o bien

data es null.

o bien

Se ha producido un error al abrir la secuencia.

o bien

No hubo respuesta del servidor que hospeda el recurso.

o bien

El valor del encabezado Content-type no es null ni application/x-www-form-urlencoded.

Comentarios

El UploadValues método envía un NameValueCollection objeto a un recurso mediante el método especificado en el method parámetro y devuelve cualquier respuesta del servidor. Este método se bloquea al cargar los datos. Para continuar ejecutándose mientras espera la respuesta del servidor, use uno de los UploadValuesAsync métodos .

Si el Content-type encabezado es null, el UploadValues método lo application/x-www-form-urlencodedestablece en .

Si el method parámetro especifica un verbo que el servidor no entiende, las clases de protocolo subyacentes determinan lo que ocurre. Normalmente, se produce una WebException excepción con la Status propiedad establecida para indicar el error.

Si la BaseAddress propiedad no es una cadena vacía ("") y address no contiene un URI absoluto, address debe ser un URI relativo combinado con BaseAddress para formar el URI absoluto de los datos solicitados. Si la QueryString propiedad no es una cadena vacía, se anexa a address.

Nota

Este miembro genera información de seguimiento cuando se habilita el seguimiento de red en la aplicación. Para obtener más información, vea Seguimiento de red en .NET Framework.

Se aplica a