WebClient.OpenWrite Metodo

Definizione

Apre un flusso per la scrittura di dati su una risorsa con l'URI specificato.

Overload

OpenWrite(String)

Apre un flusso per la scrittura di dati nella risorsa specificata.

OpenWrite(Uri)

Apre un flusso per la scrittura di dati nella risorsa specificata.

OpenWrite(String, String)

Apre un flusso per la scrittura dei dati nella risorsa specificata utilizzando il metodo specificato.

OpenWrite(Uri, String)

Apre un flusso per la scrittura dei dati nella risorsa specificata utilizzando il metodo specificato.

OpenWrite(String)

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

Apre un flusso per la scrittura di dati nella risorsa specificata.

public:
 System::IO::Stream ^ OpenWrite(System::String ^ address);
public System.IO.Stream OpenWrite (string address);
member this.OpenWrite : string -> System.IO.Stream
Public Function OpenWrite (address As String) As Stream

Parametri

address
String

L'URI della risorsa per ricevere i dati.

Restituisce

Un Stream utilizzato per scrivere i dati nella risorsa.

Eccezioni

Il valore del parametro address è null.

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

-oppure-

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

Esempio

L'esempio di codice seguente legge i dati dalla riga di comando e usa OpenWrite per ottenere un flusso per la scrittura dei dati. Il restituito da OpenWrite viene chiuso dopo l'invio Stream dei dati.

String^ uriString;
Console::Write( "\nPlease enter the URI to post data to: " );
uriString = Console::ReadLine();
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
// Apply Ascii Encoding to obtain an array of bytes.
array<Byte>^ postArray = Encoding::ASCII->GetBytes( postData );

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

// postStream implicitly sets HTTP POST as the request method.
Console::WriteLine( "Uploading to {0} ...", uriString );
Stream^ postStream = myWebClient->OpenWrite( uriString );

postStream->Write( postArray, 0, postArray->Length );

// Close the stream and release resources.
postStream->Close();

Console::WriteLine( "\nSuccessfully posted the data." );
string uriString;
Console.Write("\nPlease enter the URI to post data to : ");
uriString = Console.ReadLine();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
string postData = Console.ReadLine();
// Apply Ascii Encoding to obtain an array of bytes. 
byte[] postArray = Encoding.ASCII.GetBytes(postData);

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

// postStream implicitly sets HTTP POST as the request method.
Console.WriteLine("Uploading to {0} ...",  uriString);							Stream postStream = myWebClient.OpenWrite(uriString);

postStream.Write(postArray,0,postArray.Length);

// Close the stream and release resources.
postStream.Close();

Console.WriteLine("\nSuccessfully posted the data.");
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to : ")
uriString = Console.ReadLine()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)

Dim postData As String = Console.ReadLine()

' Apply ASCII Encoding to obtain an array of bytes .
Dim postArray As Byte() = Encoding.ASCII.GetBytes(postData)

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

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

' OpenWrite implicitly sets HTTP POST as the request method.
Dim postStream As Stream = myWebClient.OpenWrite(uriString)
postStream.Write(postArray, 0, postArray.Length)

' Close the stream and release resources.
postStream.Close()

Console.WriteLine(ControlChars.Cr + "Successfully posted the data.")

Commenti

Il OpenWrite metodo restituisce un flusso scrivibile utilizzato per inviare dati a una risorsa. Questo metodo blocca durante l'apertura del flusso. Per continuare l'esecuzione durante l'attesa del flusso, usare uno dei OpenWriteAsync metodi.

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

OpenWrite(Uri)

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

Apre un flusso per la scrittura di dati nella risorsa specificata.

public:
 System::IO::Stream ^ OpenWrite(Uri ^ address);
public System.IO.Stream OpenWrite (Uri address);
member this.OpenWrite : Uri -> System.IO.Stream
Public Function OpenWrite (address As Uri) As Stream

Parametri

address
Uri

L'URI della risorsa per ricevere i dati.

Restituisce

Un Stream utilizzato per scrivere i dati nella risorsa.

Eccezioni

Il valore del parametro address è null.

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

-oppure-

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

Commenti

Il OpenWrite metodo restituisce un flusso scrivibile utilizzato per inviare dati a una risorsa. Questo metodo blocca durante l'apertura del flusso. Per continuare l'esecuzione durante l'attesa del flusso, usare uno dei OpenWriteAsync metodi.

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

OpenWrite(String, String)

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

Apre un flusso per la scrittura dei dati nella risorsa specificata utilizzando il metodo specificato.

public:
 System::IO::Stream ^ OpenWrite(System::String ^ address, System::String ^ method);
public System.IO.Stream OpenWrite (string address, string? method);
public System.IO.Stream OpenWrite (string address, string method);
member this.OpenWrite : string * string -> System.IO.Stream
Public Function OpenWrite (address As String, method As String) As Stream

Parametri

address
String

L'URI della risorsa per ricevere i dati.

method
String

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

Restituisce

Un Stream utilizzato per scrivere i dati nella risorsa.

Eccezioni

Il valore del parametro address è null.

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

-oppure-

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

Esempio

L'esempio di codice seguente legge i dati dalla riga di comando e usa OpenWrite per ottenere un flusso usato per scrivere i dati. L'oggetto Stream restituito da OpenWrite deve essere chiuso per inviare i dati.

String^ uriString;
Console::Write( "\nPlease enter the URI to post data to: " );
uriString = Console::ReadLine();
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
// Apply ASCII encoding to obtain an array of bytes .
array<Byte>^ postArray = Encoding::ASCII->GetBytes( postData );

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

Console::WriteLine( "Uploading to {0} ...", uriString );
Stream^ postStream = myWebClient->OpenWrite( uriString, "POST" );
postStream->Write( postArray, 0, postArray->Length );

// Close the stream and release resources.
postStream->Close();
Console::WriteLine( "\nSuccessfully posted the data." );
string uriString;
Console.Write("\nPlease enter the URI to post data to : ");
uriString = Console.ReadLine();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
string postData = Console.ReadLine();
// Apply ASCII encoding to obtain an array of bytes .
byte[] postArray = Encoding.ASCII.GetBytes(postData);

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

Console.WriteLine("Uploading to {0} ...",  uriString);						
Stream postStream = myWebClient.OpenWrite(uriString,"POST");
postStream.Write(postArray,0,postArray.Length);

// Close the stream and release resources.
postStream.Close();
Console.WriteLine("\nSuccessfully posted the data.");
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to : ")
uriString = Console.ReadLine()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
' Apply ASCII encoding to obtain an array of bytes.
Dim postArray As Byte() = Encoding.ASCII.GetBytes(postData)

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

Console.WriteLine("Uploading to {0} ...", uriString)
Dim postStream As Stream = myWebClient.OpenWrite(uriString, "POST")

postStream.Write(postArray, 0, postArray.Length)

' Close the stream and release resources.
postStream.Close()

Console.WriteLine(ControlChars.Cr + "Successfully posted the data.")

Commenti

Il OpenWrite metodo restituisce un flusso scrivibile utilizzato per inviare dati a una risorsa. La richiesta sottostante viene effettuata con il metodo specificato nel method parametro. I dati vengono inviati al server quando si chiude il flusso. Questo metodo blocca durante l'apertura del flusso. Per continuare l'esecuzione durante l'attesa del flusso, usare uno dei OpenWriteAsync metodi.

Se il method parametro specifica un metodo non compreso dal server, le classi di protocollo sottostanti determinano cosa 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 specifica un indirizzo 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

OpenWrite(Uri, String)

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

Apre un flusso per la scrittura dei dati nella risorsa specificata utilizzando il metodo specificato.

public:
 System::IO::Stream ^ OpenWrite(Uri ^ address, System::String ^ method);
public System.IO.Stream OpenWrite (Uri address, string? method);
public System.IO.Stream OpenWrite (Uri address, string method);
member this.OpenWrite : Uri * string -> System.IO.Stream
Public Function OpenWrite (address As Uri, method As String) As Stream

Parametri

address
Uri

L'URI della risorsa per ricevere i dati.

method
String

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

Restituisce

Un Stream utilizzato per scrivere i dati nella risorsa.

Eccezioni

Il valore del parametro address è null.

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

-oppure-

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

Commenti

Il OpenWrite metodo restituisce un flusso scrivibile utilizzato per inviare dati a una risorsa. Questo metodo blocca durante l'apertura del flusso. Per continuare l'esecuzione durante l'attesa del flusso, usare uno dei OpenWriteAsync metodi.

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