WebClient.UploadValues Método
Definição
Faz upload de uma coleção nome/valor para um recurso com o URI especificado.Uploads a name/value collection to a resource with the specified URI.
Sobrecargas
| UploadValues(String, NameValueCollection) |
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI especificado.Uploads the specified name/value collection to the resource identified by the specified URI. |
| UploadValues(Uri, NameValueCollection) |
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI especificado.Uploads the specified name/value collection to the resource identified by the specified URI. |
| UploadValues(String, String, NameValueCollection) |
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI determinado, usando o método indicado.Uploads the specified name/value collection to the resource identified by the specified URI, using the specified method. |
| UploadValues(Uri, String, NameValueCollection) |
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI determinado, usando o método indicado.Uploads the specified name/value collection to the resource identified by the specified URI, using the specified method. |
UploadValues(String, NameValueCollection)
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI especificado.Uploads the specified name/value collection to the resource identified by the specified URI.
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
O URI do recurso para receber a coleção.The URI of the resource to receive the collection.
- data
- NameValueCollection
O NameValueCollection para enviar para o recurso.The NameValueCollection to send to the resource.
Retornos
- Byte[]
Uma matriz Byte que contém o corpo da resposta do recurso.A Byte array containing the body of the response from the resource.
Exceções
O parâmetro address é null.The address parameter is null.
- ou --or-
O parâmetro data é null.The data parameter is null.
O URI formado pela combinação de BaseAddress e address é inválido.The URI formed by combining BaseAddress, and address is invalid.
- ou --or-
data é null.data is null.
- ou --or-
Não houve resposta do servidor que hospeda o recurso.There was no response from the server hosting the resource.
- ou --or-
Erro ao abrir o fluxo.An error occurred while opening the stream.
- ou --or-
O cabeçalho Content-type não é null ou “application/x-www-form-urlencoded”.The Content-type header is not null or "application/x-www-form-urlencoded".
Exemplos
O exemplo de código a seguir coleta informações do usuário (nome, idade e endereço) e posta os valores no servidor usando UploadValues .The following code example gathers information from the user (name, age, and address) and posts the values to the server using UploadValues. Qualquer resposta do servidor é exibida no console do.Any response from the server is displayed on the 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))
Comentários
O UploadValues método envia um NameValueCollection para um servidor.The UploadValues method sends a NameValueCollection to a server. Esse método é bloqueado durante o carregamento dos dados.This method blocks while uploading the data. Para continuar a execução enquanto aguarda a resposta do servidor, use um dos UploadValuesAsync métodos.To continue executing while waiting for the server's response, use one of the UploadValuesAsync methods.
Se a solicitação subjacente não for compreendida pelo servidor, as classes de protocolo subjacentes determinarão o que ocorre.If the underlying request is not understood by the server, the underlying protocol classes determine what occurs. Normalmente, um WebException é lançado com a Status propriedade definida para indicar o erro.Typically, a WebException is thrown with the Status property set to indicate the error.
Se o cabeçalho Content-Type for null , o UploadValues método o definirá como "application/x-www-form-urlencoded".If the Content-type header is null, the UploadValues method sets it to "application/x-www-form-urlencoded".
Se a BaseAddress propriedade não for uma cadeia de caracteres vazia ("") e não address contiver um URI absoluto, address deverá ser um URI relativo que é combinado com BaseAddress para formar o URI absoluto dos dados solicitados.If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. Se a QueryString propriedade não for uma cadeia de caracteres vazia, ela será anexada address .If the QueryString property is not an empty string, it is appended to address.
Esse método usa o comando arma para carregar um recurso de FTP.This method uses the STOR command to upload an FTP resource. Para um recurso HTTP, o método POST é usado.For an HTTP resource, the POST method is used.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede em .NET Framework.For more information, see Network Tracing in .NET Framework.
Aplica-se a
UploadValues(Uri, NameValueCollection)
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI especificado.Uploads the specified name/value collection to the resource identified by the specified URI.
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
O URI do recurso para receber a coleção.The URI of the resource to receive the collection.
- data
- NameValueCollection
O NameValueCollection para enviar para o recurso.The NameValueCollection to send to the resource.
Retornos
- Byte[]
Uma matriz Byte que contém o corpo da resposta do recurso.A Byte array containing the body of the response from the resource.
Exceções
O parâmetro address é null.The address parameter is null.
- ou --or-
O parâmetro data é null.The data parameter is null.
O URI formado pela combinação de BaseAddress e address é inválido.The URI formed by combining BaseAddress, and address is invalid.
- ou --or-
data é null.data is null.
- ou --or-
Não houve resposta do servidor que hospeda o recurso.There was no response from the server hosting the resource.
- ou --or-
Erro ao abrir o fluxo.An error occurred while opening the stream.
- ou --or-
O cabeçalho Content-type não é null ou “application/x-www-form-urlencoded”.The Content-type header is not null or "application/x-www-form-urlencoded".
Comentários
O UploadValues método envia um NameValueCollection para um servidor.The UploadValues method sends a NameValueCollection to a server. Esse método é bloqueado durante o carregamento dos dados.This method blocks while uploading the data. Para continuar a execução enquanto aguarda a resposta do servidor, use um dos UploadValuesAsync métodos.To continue executing while waiting for the server's response, use one of the UploadValuesAsync methods.
Se a solicitação subjacente não for compreendida pelo servidor, as classes de protocolo subjacentes determinarão o que ocorre.If the underlying request is not understood by the server, the underlying protocol classes determine what occurs. Normalmente, um WebException é lançado com a Status propriedade definida para indicar o erro.Typically, a WebException is thrown with the Status property set to indicate the error.
Se o cabeçalho Content-Type for null , o UploadValues método o definirá como "application/x-www-form-urlencoded".If the Content-type header is null, the UploadValues method sets it to "application/x-www-form-urlencoded".
Se a BaseAddress propriedade não for uma cadeia de caracteres vazia ("") e não address contiver um URI absoluto, address deverá ser um URI relativo que é combinado com BaseAddress para formar o URI absoluto dos dados solicitados.If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. Se a QueryString propriedade não for uma cadeia de caracteres vazia, ela será anexada address .If the QueryString property is not an empty string, it is appended to address.
Esse método usa o comando arma para carregar um recurso de FTP.This method uses the STOR command to upload an FTP resource. Para um recurso HTTP, o método POST é usado.For an HTTP resource, the POST method is used.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede em .NET Framework.For more information, see Network Tracing in .NET Framework.
Aplica-se a
UploadValues(String, String, NameValueCollection)
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI determinado, usando o método indicado.Uploads the specified name/value collection to the resource identified by the specified URI, using the specified method.
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
O URI do recurso para receber a coleção.The URI of the resource to receive the collection.
- method
- String
O método HTTP usado para enviar o arquivo para o recurso.The HTTP method used to send the file to the resource. Se for nulo, o padrão será POST para http e STOR para ftp.If null, the default is POST for http and STOR for ftp.
- data
- NameValueCollection
O NameValueCollection para enviar para o recurso.The NameValueCollection to send to the resource.
Retornos
- Byte[]
Uma matriz Byte que contém o corpo da resposta do recurso.A Byte array containing the body of the response from the resource.
Exceções
O parâmetro address é null.The address parameter is null.
- ou --or-
O parâmetro data é null.The data parameter is null.
O URI formado pela combinação de BaseAddress e address é inválido.The URI formed by combining BaseAddress, and address is invalid.
- ou --or-
data é null.data is null.
- ou --or-
Erro ao abrir o fluxo.An error occurred while opening the stream.
- ou --or-
Não houve resposta do servidor que hospeda o recurso.There was no response from the server hosting the resource.
- ou --or-
O valor do cabeçalho Content-type não é null nem application/x-www-form-urlencoded.The Content-type header value is not null and is not application/x-www-form-urlencoded.
Exemplos
O exemplo de código a seguir coleta informações do usuário (nome, idade e endereço) e posta os valores no servidor usando UploadValues .The following code example gathers information from the user (name, age, and address) and posts the values to the server using UploadValues. Qualquer resposta do servidor é exibida no console do.Any response from the server is displayed on the 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))
Comentários
O UploadValues método envia um NameValueCollection para um recurso usando o método especificado no method parâmetro e retorna qualquer resposta do servidor.The UploadValues method sends a NameValueCollection to a resource using the method specified in the method parameter and returns any response from the server. Esse método é bloqueado durante o carregamento dos dados.This method blocks while uploading the data. Para continuar a execução enquanto aguarda a resposta do servidor, use um dos UploadValuesAsync métodos.To continue executing while waiting for the server's response, use one of the UploadValuesAsync methods.
Se o Content-type cabeçalho for null , o UploadValues método o definirá como application/x-www-form-urlencoded .If the Content-type header is null, the UploadValues method sets it to application/x-www-form-urlencoded.
Se o method parâmetro especificar um verbo que não é compreendido pelo servidor, as classes de protocolo subjacentes determinarão o que ocorre.If the method parameter specifies a verb that is not understood by the server, the underlying protocol classes determine what occurs. Normalmente, um WebException é lançado com a Status propriedade definida para indicar o erro.Typically, a WebException is thrown with the Status property set to indicate the error.
Se a BaseAddress propriedade não for uma cadeia de caracteres vazia ("") e não address contiver um URI absoluto, address deverá ser um URI relativo que é combinado com BaseAddress para formar o URI absoluto dos dados solicitados.If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. Se a QueryString propriedade não for uma cadeia de caracteres vazia, ela será anexada address .If the QueryString property is not an empty string, it is appended to address.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede em .NET Framework.For more information, see Network Tracing in .NET Framework.
Aplica-se a
UploadValues(Uri, String, NameValueCollection)
Carrega a coleção de nome/valor especificada no recurso identificado pelo URI determinado, usando o método indicado.Uploads the specified name/value collection to the resource identified by the specified URI, using the specified method.
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
O URI do recurso para receber a coleção.The URI of the resource to receive the collection.
- method
- String
O método HTTP usado para enviar o arquivo para o recurso.The HTTP method used to send the file to the resource. Se for nulo, o padrão será POST para http e STOR para ftp.If null, the default is POST for http and STOR for ftp.
- data
- NameValueCollection
O NameValueCollection para enviar para o recurso.The NameValueCollection to send to the resource.
Retornos
- Byte[]
Uma matriz Byte que contém o corpo da resposta do recurso.A Byte array containing the body of the response from the resource.
Exceções
O parâmetro address é null.The address parameter is null.
- ou --or-
O parâmetro data é null.The data parameter is null.
O URI formado pela combinação de BaseAddress e address é inválido.The URI formed by combining BaseAddress, and address is invalid.
- ou --or-
data é null.data is null.
- ou --or-
Erro ao abrir o fluxo.An error occurred while opening the stream.
- ou --or-
Não houve resposta do servidor que hospeda o recurso.There was no response from the server hosting the resource.
- ou --or-
O valor do cabeçalho Content-type não é null nem application/x-www-form-urlencoded.The Content-type header value is not null and is not application/x-www-form-urlencoded.
Comentários
O UploadValues método envia um NameValueCollection para um recurso usando o método especificado no method parâmetro e retorna qualquer resposta do servidor.The UploadValues method sends a NameValueCollection to a resource using the method specified in the method parameter and returns any response from the server. Esse método é bloqueado durante o carregamento dos dados.This method blocks while uploading the data. Para continuar a execução enquanto aguarda a resposta do servidor, use um dos UploadValuesAsync métodos.To continue executing while waiting for the server's response, use one of the UploadValuesAsync methods.
Se o Content-type cabeçalho for null , o UploadValues método o definirá como application/x-www-form-urlencoded .If the Content-type header is null, the UploadValues method sets it to application/x-www-form-urlencoded.
Se o method parâmetro especificar um verbo que não é compreendido pelo servidor, as classes de protocolo subjacentes determinarão o que ocorre.If the method parameter specifies a verb that is not understood by the server, the underlying protocol classes determine what occurs. Normalmente, um WebException é lançado com a Status propriedade definida para indicar o erro.Typically, a WebException is thrown with the Status property set to indicate the error.
Se a BaseAddress propriedade não for uma cadeia de caracteres vazia ("") e não address contiver um URI absoluto, address deverá ser um URI relativo que é combinado com BaseAddress para formar o URI absoluto dos dados solicitados.If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. Se a QueryString propriedade não for uma cadeia de caracteres vazia, ela será anexada address .If the QueryString property is not an empty string, it is appended to address.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede em .NET Framework.For more information, see Network Tracing in .NET Framework.