Compartir vía


WebClient.UploadValues Método

Definición

Carga una colección name/value en un recurso con el URI especificado.

Sobrecargas

UploadValues(String, NameValueCollection)

Carga la colección name/value especificada en el recurso identificado por el URI especificado.

UploadValues(Uri, NameValueCollection)

Carga la colección name/value especificada en el recurso identificado por el URI especificado.

UploadValues(String, String, NameValueCollection)

Carga la colección name/value especificada en el recurso identificado por el URI especificado mediante el método especificado.

UploadValues(Uri, String, NameValueCollection)

Carga la colección name/value especificada en el recurso identificado por el URI especificado mediante el método especificado.

UploadValues(String, NameValueCollection)

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

Carga la colección name/value especificada en el recurso identificado por 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

Identificador URI del recurso que se va a recibir la colección.

data
NameValueCollection

El NameValueCollection que se va a enviar al recurso.

Devoluciones

Byte[]

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

Excepciones

El parámetro address es null.

-o-

El parámetro data es null.

El URI formado mediante la combinación de BaseAddressy address no es válido.

-o-

data es null.

-o-

No se ha producido ninguna respuesta del servidor que hospeda el recurso.

-o-

Error al abrir la secuencia.

-o-

El 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 envía los valores al 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

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

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

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

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

Si la propiedad BaseAddress 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 propiedad QueryString 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 al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte seguimiento de red de en .NET Framework.

Se aplica a

UploadValues(Uri, NameValueCollection)

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

Carga la colección name/value especificada en el recurso identificado por 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

Identificador URI del recurso que se va a recibir la colección.

data
NameValueCollection

El NameValueCollection que se va a enviar al recurso.

Devoluciones

Byte[]

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

Excepciones

El parámetro address es null.

-o-

El parámetro data es null.

El URI formado mediante la combinación de BaseAddressy address no es válido.

-o-

data es null.

-o-

No se ha producido ninguna respuesta del servidor que hospeda el recurso.

-o-

Error al abrir la secuencia.

-o-

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

Comentarios

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

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

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

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

Si la propiedad BaseAddress 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 propiedad QueryString 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 al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte seguimiento de red de en .NET Framework.

Se aplica a

UploadValues(String, String, NameValueCollection)

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

Carga la colección name/value especificada en el recurso identificado por el URI especificado mediante 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

Identificador URI del recurso que se va a recibir la colección.

method
String

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

data
NameValueCollection

El NameValueCollection que se va a enviar al recurso.

Devoluciones

Byte[]

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

Excepciones

El parámetro address es null.

-o-

El parámetro data es null.

El URI formado mediante la combinación de BaseAddressy address no es válido.

-o-

data es null.

-o-

Error al abrir la secuencia.

-o-

No se ha producido ninguna respuesta del servidor que hospeda el recurso.

-o-

El valor del encabezado Content-type no es null y no es 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 envía los valores al 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

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

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

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

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

Si la propiedad BaseAddress 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 propiedad QueryString no es una cadena vacía, se anexa a address.

Nota

Este miembro genera información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte seguimiento de red de en .NET Framework.

Se aplica a

UploadValues(Uri, String, NameValueCollection)

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

Carga la colección name/value especificada en el recurso identificado por el URI especificado mediante 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

Identificador URI del recurso que se va a recibir la colección.

method
String

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

data
NameValueCollection

El NameValueCollection que se va a enviar al recurso.

Devoluciones

Byte[]

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

Excepciones

El parámetro address es null.

-o-

El parámetro data es null.

El URI formado mediante la combinación de BaseAddressy address no es válido.

-o-

data es null.

-o-

Error al abrir la secuencia.

-o-

No se ha producido ninguna respuesta del servidor que hospeda el recurso.

-o-

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

Comentarios

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

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

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

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

Si la propiedad BaseAddress 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 propiedad QueryString no es una cadena vacía, se anexa a address.

Nota

Este miembro genera información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, consulte seguimiento de red de en .NET Framework.

Se aplica a