다음을 통해 공유


WebRequest.GetRequestStream 메서드

정의

하위 클래스에서 재정의되는 경우 인터넷 리소스에 데이터를 쓰기 위한 Stream 반환합니다.

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

반환

인터넷 리소스에 데이터를 쓰기 위한 Stream.

예외

메서드가 하위 클래스에서 재정의되지 않은 경우 메서드에 액세스하려고 시도합니다.

예제

다음 예제에서는 GetRequestStream 메서드를 사용하여 스트림을 가져온 다음 해당 스트림 데이터를 씁니다.

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

설명

주의

WebRequest, HttpWebRequest, ServicePointWebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.

GetRequestStream 메서드는 인터넷 리소스에 데이터를 보내는 요청을 시작하고 인터넷 리소스에 데이터를 보내기 위한 Stream 인스턴스를 반환합니다.

GetRequestStream 메서드는 Stream대한 동기 액세스를 제공합니다. 비동기 액세스의 경우 BeginGetRequestStreamEndGetRequestStream 메서드를 사용합니다.

메모

WebRequest 클래스는 abstract 클래스입니다. 런타임에 WebRequest 인스턴스의 실제 동작은 WebRequest.Create 메서드에서 반환된 하위 클래스에 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 HttpWebRequestFileWebRequest같은 하위 클래스에 대한 설명서를 참조하세요.

적용 대상

추가 정보