Share via


WebRequest.GetRequestStream Metoda

Definice

Při přepsání v potomkované třídě vrátí hodnotu Stream pro zápis dat do internetového prostředku.

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

Návraty

A Stream pro zápis dat do internetového prostředku.

Výjimky

Jakýkoli pokus o přístup k metodě, pokud metoda není přepsána v následné třídě.

Příklady

Následující příklad používá metodu GetRequestStream k získání datového proudu a pak zapíše data, která streamují.

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

Poznámky

Metoda GetRequestStream zahájí požadavek na odeslání dat do internetového prostředku a vrátí Stream instanci pro odesílání dat do internetového prostředku.

Metoda GetRequestStream poskytuje synchronní přístup k .Stream Pro asynchronní přístup použijte BeginGetRequestStream metody a EndGetRequestStream .

Poznámka

Třída WebRequest je abstract třída. Skutečné chování WebRequest instancí za běhu je určeno následnou třídou vrácenou metodou WebRequest.Create . Další informace o výchozích hodnotách a výjimkách najdete v dokumentaci pro odvozené třídy, například HttpWebRequest a FileWebRequest.

Platí pro

Viz také