FileWebRequest.GetRequestStream 메서드

정의

파일 시스템 리소스에 데이터를 쓰기 위한 Stream 개체를 반환합니다.

public:
 override System::IO::Stream ^ GetRequestStream();
public override System.IO.Stream GetRequestStream ();
override this.GetRequestStream : unit -> System.IO.Stream
Public Overrides Function GetRequestStream () As Stream

반환

Stream

파일 시스템 리소스에 데이터를 쓰기 위한 Stream입니다.

예외

요청 시간이 초과된 경우

예제

다음 코드 예제에서는 메서드를 GetRequestStream 사용하여 파일에 쓰는 데 사용되는 스트림 인스턴스를 가져옵니다. 클래스의 전체 예제를 FileWebRequest 참조하세요.

// Enter the string to write into the file.
Console::WriteLine( "Enter the string you want to write:" );
String^ userInput = Console::ReadLine();

// Convert the string to Byte array.
ASCIIEncoding^ encoder = gcnew ASCIIEncoding;
array<Byte>^byteArray = encoder->GetBytes( userInput );

// Set the ContentLength property.
myFileWebRequest->ContentLength = byteArray->Length;
String^ contentLength = myFileWebRequest->ContentLength.ToString();
Console::WriteLine( "\nThe content length is {0}.", contentLength );

// Get the file stream handler to write into the file.
Stream^ readStream = myFileWebRequest->GetRequestStream();

// Write to the file stream.
// Note. In order for this to work the file must be accessible
// on the network. This can be accomplished by setting the property
// sharing of the folder containg the file. The permissions
// can be set so everyone can modify the file.
// FileWebRequest::Credentials property cannot be used for this purpose.
readStream->Write( byteArray, 0, userInput->Length );
Console::WriteLine( "\nThe String you entered was successfully written into the file." );
// Enter the string to write to the file.
Console.WriteLine ("Enter the string you want to write:");

string userInput = Console.ReadLine ();

// Convert the string to a byte array.
ASCIIEncoding encoder = new ASCIIEncoding ();
byte[] byteArray = encoder.GetBytes (userInput);

// Set the ContentLength property.
myFileWebRequest.ContentLength = byteArray.Length;

string contentLength = myFileWebRequest.ContentLength.ToString ();

Console.WriteLine ("\nThe content length is {0}.", contentLength);

// Get the file stream handler to write to the file.
Stream readStream = myFileWebRequest.GetRequestStream ();

// Write to the file stream.
// Note.  For this to work, the file must be accessible
// on the network. This can be accomplished by setting the property
// sharing of the folder containg the file.
// FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write (byteArray, 0, userInput.Length);
Console.WriteLine ("\nThe String you entered was successfully written to the file.");
' Enter the string to write to the file.
Console.WriteLine("Enter the string you want to write:")
Dim userInput As String = Console.ReadLine()

' Convert the string to a byte array.
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte() = encoder.GetBytes(userInput)

' Set the ContentLength property.
myFileWebRequest.ContentLength = byteArray.Length

Dim contentLength As String = myFileWebRequest.ContentLength.ToString()

Console.WriteLine(ControlChars.Lf + "The content length is {0}.", contentLength)


' Get the file stream handler to write to the file.
Dim readStream As Stream = myFileWebRequest.GetRequestStream()

' Write to the stream. 
' Note. For this to work the file must be accessible
' on the network. This can be accomplished by setting the property
' sharing of the folder containg the file.  
' FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write(byteArray, 0, userInput.Length)


Console.WriteLine(ControlChars.Lf + "The String you entered was successfully written to the file.")

설명

메서드는 GetRequestStream .에 Stream대한 동기 액세스를 제공합니다. 비동기 액세스의 경우 해당 및 EndGetRequestStream 메서드를 BeginGetRequestStream 사용합니다.

적용 대상

추가 정보