WebRequest.GetRequestStream Metodo

Definizione

Quando ne viene eseguito l'override in una classe discendente, restituisce un oggetto Stream per la scrittura di dati nella risorsa Internet.

public:
 virtual System::IO::Stream ^ GetRequestStream();
public virtual System.IO.Stream GetRequestStream ();
abstract member GetRequestStream : unit -> System.IO.Stream
override this.GetRequestStream : unit -> System.IO.Stream
Public Overridable Function GetRequestStream () As Stream

Restituisce

Stream

Oggetto Stream per la scrittura dei dati nella risorsa Internet.

Eccezioni

Viene eseguito un tentativo di accedere al metodo quando quest'ultimo non è sottoposto a override in una classe discendente.

Esempio

Nell'esempio seguente viene usato il GetRequestStream metodo per ottenere un flusso e quindi scrivere i dati che il flusso.

// Set the 'ContentType' property of the WebRequest.
myWebRequest->ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest->ContentLength = byteArray->Length;
Stream^ newStream = myWebRequest->GetRequestStream();
newStream->Write( byteArray, 0, byteArray->Length );

// Close the Stream object.
newStream->Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType="application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength=byteArray.Length;
Stream newStream=myWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);

// Close the Stream object.
newStream.Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();


' Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)

' Close the Stream object.
newStream.Close()

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

Commenti

Il GetRequestStream metodo avvia una richiesta per inviare dati alla risorsa Internet e restituisce un'istanza Stream per l'invio di dati alla risorsa Internet.

Il GetRequestStream metodo fornisce l'accesso sincrono all'oggetto Stream. Per l'accesso asincrono, usare i BeginGetRequestStream metodi e EndGetRequestStream .

Nota

La WebRequest classe è una abstract classe. Il comportamento effettivo delle istanze in fase di WebRequest esecuzione è determinato dalla classe discendente restituita dal WebRequest.Create metodo . Per altre informazioni sui valori e le eccezioni predefiniti, vedere la documentazione per le classi discendenti, ad esempio HttpWebRequest e FileWebRequest.

Si applica a

Vedi anche