FtpWebRequest.BeginGetRequestStream(AsyncCallback, Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
쓰기를 위해 요청의 콘텐츠 스트림을 비동기적으로 열기 시작합니다.
public:
override IAsyncResult ^ BeginGetRequestStream(AsyncCallback ^ callback, System::Object ^ state);
public override IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state);
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);
override this.BeginGetRequestStream : AsyncCallback * obj -> IAsyncResult
Public Overrides Function BeginGetRequestStream (callback As AsyncCallback, state As Object) As IAsyncResult
매개 변수
- callback
- AsyncCallback
AsyncCallback 작업이 완료되면 호출할 메서드를 참조하는 대리자입니다.
- state
- Object
작업에 대한 정보를 포함하는 사용자 정의 개체입니다. 이 개체는 작업이 완료되면 대리자에게 callback 전달됩니다.
반품
IAsyncResult 작업의 상태를 나타내는 인스턴스입니다.
예외
이 메서드에 대한 이전 호출이거나 GetRequestStream() 아직 완료되지 않았습니다.
FTP 서버에 대한 연결을 설정할 수 없습니다.
속성이 Method .로 UploadFile설정되지 않았습니다.
예제
다음 코드 예제에서는 요청의 스트림을 가져오기 위해 비동기 작업을 시작하는 방법을 보여 줍니다. 이 코드 예제는 클래스 개요에 제공된 더 큰 예제의 FtpWebRequest 일부입니다.
// Command line arguments are two strings:
// 1. The url that is the name of the file being uploaded to the server.
// 2. The name of the file on the local machine.
//
public static void Main(string[] args)
{
// Create a Uri instance with the specified URI string.
// If the URI is not correctly formed, the Uri constructor
// will throw an exception.
ManualResetEvent waitObject;
Uri target = new Uri (args[0]);
string fileName = args[1];
FtpState state = new FtpState();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example uses anonymous logon.
// The request is anonymous by default; the credential does not have to be specified.
// The example specifies the credential only to
// control how actions are logged on the server.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
// Store the request in the object that we pass into the
// asynchronous operations.
state.Request = request;
state.FileName = fileName;
// Get the event to wait on.
waitObject = state.OperationComplete;
// Asynchronously get the stream for the file contents.
request.BeginGetRequestStream(
new AsyncCallback (EndGetStreamCallback),
state
);
// Block the current thread until all operations are complete.
waitObject.WaitOne();
// The operations either completed or threw an exception.
if (state.OperationException != null)
{
throw state.OperationException;
}
else
{
Console.WriteLine("The operation completed - {0}", state.StatusDescription);
}
}
설명
메서드를 호출 EndGetRequestStream 하여 비동기 작업을 완료해야 합니다. 일반적으로 . EndGetRequestStreamcallback 작업의 상태를 확인하려면 이 메서드에서 반환된 개체의 IAsyncResult 속성을 확인합니다.
이 메서드는 스트림을 기다리는 동안 차단되지 않습니다. 차단하려면 이 메서드 대신 호출 GetRequestStream 합니다.
비동기 프로그래밍 모델 사용에 대한 자세한 내용은 동기 메서드를 비동기적으로 호출하는 방법을 참조하세요.
메모
이 멤버는 애플리케이션에서 네트워크 추적을 사용하도록 설정할 때 추적 정보를 출력합니다. 자세한 내용은 .NET Framework의Network 추적 참조하세요.
호출자 참고
이 메서드는 네트워크 트래픽을 생성합니다.