WebRequest.GetRequestStream WebRequest.GetRequestStream WebRequest.GetRequestStream WebRequest.GetRequestStream Method

定义

当在子类中重写时,返回用于将数据写入 Internet 资源的 StreamWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource.

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

返回

用于将数据写入 Internet 资源的 StreamA Stream for writing data to the Internet resource.

异常

当未在子类中重写该方法时,试图访问该方法。Any attempt is made to access the method, when the method is not overridden in a descendant class.

示例

下面的示例使用GetRequestStream方法来获取流,然后写入流式传输的数据。The following example uses the GetRequestStream method to obtain a stream and then writes data that stream.

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

注解

方法启动向 internet 资源发送数据的请求,并Stream返回用于将数据发送到 internet 资源的实例。 GetRequestStreamThe GetRequestStream method initiates a request to send data to the Internet resource and returns a Stream instance for sending data to the Internet resource.

方法提供对的Stream同步访问。 GetRequestStreamThe GetRequestStream method provides synchronous access to the Stream. 对于异步访问,请使用BeginGetRequestStreamEndGetRequestStream方法。For asynchronous access, use the BeginGetRequestStream and EndGetRequestStream methods.

备注

类是一个abstract类。 WebRequestThe WebRequest class is an abstract class. WebRequest实例在运行时的实际行为由WebRequest.Create方法返回的子代类确定。The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. 有关默认值和异常的详细信息,请参阅子代类的文档,例如HttpWebRequest和。 FileWebRequestFor more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

适用于

另请参阅